tx · Am7RAxgqgvi8rY2bdNnhXnbc6wFE3JshPYw8q8LMKykX 3Mtwm9zTenpozLfVL46hAidH3zuLKScURQK: -0.01400000 Waves 2021.11.18 23:59 [1796994] smart account 3Mtwm9zTenpozLfVL46hAidH3zuLKScURQK > SELF 0.00000000 Waves
{ "type": 13, "id": "Am7RAxgqgvi8rY2bdNnhXnbc6wFE3JshPYw8q8LMKykX", "fee": 1400000, "feeAssetId": null, "timestamp": 1637269170489, "version": 2, "chainId": 84, "sender": "3Mtwm9zTenpozLfVL46hAidH3zuLKScURQK", "senderPublicKey": "Eu1AYNJAMgEeS5Wftr8wEFyspBRFVBv9qQV7XCYzGpxn", "proofs": [ "pcwzsp23oQfEKmb6gJgt6kxTMfps9x8MiRXaMhpsX1UcyUY2kxWnisNBysBc1BcrqC3Mhv2VE5YRDLxiaArBsea" ], "script": "base64:AAIEAAAAAAAAAAQIAhIAAAAAAAAAAAEAAAABaQEAAAASc3dhcERhdGFGYWlsT3JSRUFEAAAAAAQAAAAGcHVia2V5CQACWAAAAAEICAUAAAABaQAAAAZjYWxsZXIAAAAFYnl0ZXMEAAAABUFkZGVkCQABLAAAAAICAAAAC1Jld2FyZHNfT2ZfBQAAAAZwdWJrZXkEAAAACWV4dHJhY3RlZAkABLUAAAACBQAAAAVBZGRlZAIAAAABXwkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACAgAAAAZwdWJrZXkFAAAABnB1YmtleQkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACAgAAAAthZGRlZHB1YmtleQUAAAAFQWRkZWQJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgIAAAAJZXh0cmFjdGVkCQABkQAAAAIFAAAACWV4dHJhY3RlZAAAAAAAAAAAAAUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmMh0hG", "height": 1796994, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 57KAy3WDXNrFtUN5iLoZSz7gLFfN8Ly4GaUPFvuWmvZc Next: GfBL1TSQCLWmM4VUwpUHWEH9RPe2ZfouFzY7qZQY5mtS Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let DISCLAIMER = "testing PUZZLE staking smart contract with rewards in multiple assets" | |
5 | - | ||
6 | - | let scale = 100000000 | |
7 | - | ||
8 | - | let puzzleId = base58'J9VzWPfRSQyCbEv5oWpxLSihigbpbJsGBHJZV9Ct8ook' | |
9 | - | ||
10 | - | let earnedAssets = [base58'Zn3cLHW7aAVPm5aACcTjvg7e7iEy2cKDtbowok5qa9H', base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p', base58'EfdcPXw7o7rrrPWmMBr2sa66Dk95n56622ngujbaGhye', base58'B543bkZcZNo5GrUnd5fxB6EwkiJhAVyKCkPn5nWzZC2s', base58'5bcAh1r6ydrpk44FEmrnmJQjumgKo3NKEEsyfgmZYwxC', base58'54UszKAj3MtYmkdRCqSXAcaQLaVALBy7CCrVkfmfzhxR', base58'5nk9JW8yRonyNBEwhChoksLxpBECVxbVLqaNuQs9EJn1', base58'Dfx6LJPndo1h5Umk9SofDhMDs6Gi8cHyT3873pSgoASU', base58'4kwKSf4Bx2Wq8YxKnVZBhcEHyXzEtJ2pw7ixfJgirwf2', base58'Ej7kEzxvUsoiMtJKiuFpMD9tC6qfCADpZynyW2vqcWW', base58'5HGPPLj58XUx3ryMgkASJoqYq33zwBbTMf1CGxfKw6jp', base58'yDf4UTg4DS75sCNP7oC1HraTN4KHtqmd6WueTid4PF1', base58'2R57nL7ftpuwbgdprcmAeA9i7ykLH6A4wzLkZHWPiHKc', base58'CE5cxMvz7865CyFZPFUmDiL4KRkYXP6b6oYgN3vmWdV5', base58'5m5stLsMZSPomwxTTjJGMMEnjMafRMfap5vZyaLwgMKD', base58'46PdJcKzDuYfzLuLNjffM3F8jR8hL357V9AdGK2xN3kx', base58'ESaD2AREvgk7o4C9eQkZ8Nmau9BSHqgTK5ymHV36xocy'] | |
11 | - | ||
12 | - | let earnedAssetsAmount = size(earnedAssets) | |
13 | - | ||
14 | - | func tryGetInteger (key) = match getInteger(this, key) { | |
15 | - | case b: Int => | |
16 | - | b | |
17 | - | case _ => | |
18 | - | 0 | |
19 | - | } | |
20 | - | ||
21 | - | ||
22 | - | func calculateCurrentAssetInterest (assetId,assetIdStr) = { | |
23 | - | let totalStaked = tryGetInteger("global_puzzleStaked") | |
24 | - | let tokenBalanceLastCheck = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")) | |
25 | - | let currentTokenEarnings = max([tokenBalanceLastCheck, assetBalance(this, assetId)]) | |
26 | - | let newEarnings = (currentTokenEarnings - tokenBalanceLastCheck) | |
27 | - | let newInterest = if ((totalStaked == 0)) | |
28 | - | then 0 | |
29 | - | else fraction(newEarnings, scale, totalStaked) | |
30 | - | let lastCheckInterest = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_interest")) | |
31 | - | (lastCheckInterest + newInterest) | |
32 | - | } | |
33 | - | ||
34 | - | ||
35 | - | func claimResult (address) = { | |
36 | - | let addressStr = toString(address) | |
37 | - | let puzzleAmount = tryGetInteger((addressStr + "_puzzleStaked")) | |
38 | - | func handler (accum,assetId) = { | |
39 | - | let assetIdStr = toBase58String(assetId) | |
40 | - | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
41 | - | let currentTokenEarnings = max([tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")), assetBalance(this, assetId)]) | |
42 | - | let rewardAmount = fraction(puzzleAmount, (currentTokenInterest - tryGetInteger((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"))), scale) | |
43 | - | if ((rewardAmount == 0)) | |
44 | - | then accum | |
45 | - | else (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), (currentTokenEarnings - rewardAmount)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest), ScriptTransfer(address, rewardAmount, assetId)]) | |
46 | - | } | |
47 | - | ||
48 | - | let $l = earnedAssets | |
49 | - | let $s = size($l) | |
50 | - | let $acc0 = nil | |
51 | - | func 1 ($a,$i) = if (($i >= $s)) | |
52 | - | then $a | |
53 | - | else handler($a, $l[$i]) | |
54 | - | ||
55 | - | func 2 ($a,$i) = if (($i >= $s)) | |
56 | - | then $a | |
57 | - | else throw("List size exceeds 17") | |
58 | - | ||
59 | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
60 | - | } | |
61 | 4 | ||
62 | 5 | ||
63 | 6 | @Callable(i) | |
64 | - | func stake () = { | |
65 | - | let addressStr = toString(i.caller) | |
66 | - | let pmt = i.payments[0] | |
67 | - | if ((value(pmt.assetId) != puzzleId)) | |
68 | - | then throw("wrong asset attached") | |
69 | - | else { | |
70 | - | func handler (accum,assetId) = { | |
71 | - | let assetIdStr = toBase58String(assetId) | |
72 | - | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
73 | - | (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), assetBalance(this, assetId)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest)]) | |
74 | - | } | |
75 | - | ||
76 | - | let li = { | |
77 | - | let $l = earnedAssets | |
78 | - | let $s = size($l) | |
79 | - | let $acc0 = nil | |
80 | - | func 1 ($a,$i) = if (($i >= $s)) | |
81 | - | then $a | |
82 | - | else handler($a, $l[$i]) | |
83 | - | ||
84 | - | func 2 ($a,$i) = if (($i >= $s)) | |
85 | - | then $a | |
86 | - | else throw("List size exceeds 17") | |
87 | - | ||
88 | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
89 | - | } | |
90 | - | (li ++ [IntegerEntry((addressStr + "_puzzleStaked"), (tryGetInteger((addressStr + "_puzzleStaked")) + pmt.amount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") + pmt.amount))]) | |
91 | - | } | |
7 | + | func swapDataFailOrREAD () = { | |
8 | + | let pubkey = toBase58String(i.caller.bytes) | |
9 | + | let Added = ("Rewards_Of_" + pubkey) | |
10 | + | let extracted = split(Added, "_") | |
11 | + | [StringEntry("pubkey", pubkey), StringEntry("addedpubkey", Added), StringEntry("extracted", extracted[0])] | |
92 | 12 | } | |
93 | - | ||
94 | - | ||
95 | - | ||
96 | - | @Callable(i) | |
97 | - | func unstake (puzzleAmount) = { | |
98 | - | let addressStr = toString(i.caller) | |
99 | - | let puzzleAvailable = tryGetInteger((addressStr + "_puzzleStaked")) | |
100 | - | if ((puzzleAmount > puzzleAvailable)) | |
101 | - | then throw("you don't have PUZZLE available") | |
102 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - puzzleAmount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") - puzzleAmount))]) | |
103 | - | } | |
104 | - | ||
105 | - | ||
106 | - | ||
107 | - | @Callable(i) | |
108 | - | func claim () = claimResult(i.caller) | |
109 | 13 | ||
110 | 14 | ||
111 | 15 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let DISCLAIMER = "testing PUZZLE staking smart contract with rewards in multiple assets" | |
5 | - | ||
6 | - | let scale = 100000000 | |
7 | - | ||
8 | - | let puzzleId = base58'J9VzWPfRSQyCbEv5oWpxLSihigbpbJsGBHJZV9Ct8ook' | |
9 | - | ||
10 | - | let earnedAssets = [base58'Zn3cLHW7aAVPm5aACcTjvg7e7iEy2cKDtbowok5qa9H', base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p', base58'EfdcPXw7o7rrrPWmMBr2sa66Dk95n56622ngujbaGhye', base58'B543bkZcZNo5GrUnd5fxB6EwkiJhAVyKCkPn5nWzZC2s', base58'5bcAh1r6ydrpk44FEmrnmJQjumgKo3NKEEsyfgmZYwxC', base58'54UszKAj3MtYmkdRCqSXAcaQLaVALBy7CCrVkfmfzhxR', base58'5nk9JW8yRonyNBEwhChoksLxpBECVxbVLqaNuQs9EJn1', base58'Dfx6LJPndo1h5Umk9SofDhMDs6Gi8cHyT3873pSgoASU', base58'4kwKSf4Bx2Wq8YxKnVZBhcEHyXzEtJ2pw7ixfJgirwf2', base58'Ej7kEzxvUsoiMtJKiuFpMD9tC6qfCADpZynyW2vqcWW', base58'5HGPPLj58XUx3ryMgkASJoqYq33zwBbTMf1CGxfKw6jp', base58'yDf4UTg4DS75sCNP7oC1HraTN4KHtqmd6WueTid4PF1', base58'2R57nL7ftpuwbgdprcmAeA9i7ykLH6A4wzLkZHWPiHKc', base58'CE5cxMvz7865CyFZPFUmDiL4KRkYXP6b6oYgN3vmWdV5', base58'5m5stLsMZSPomwxTTjJGMMEnjMafRMfap5vZyaLwgMKD', base58'46PdJcKzDuYfzLuLNjffM3F8jR8hL357V9AdGK2xN3kx', base58'ESaD2AREvgk7o4C9eQkZ8Nmau9BSHqgTK5ymHV36xocy'] | |
11 | - | ||
12 | - | let earnedAssetsAmount = size(earnedAssets) | |
13 | - | ||
14 | - | func tryGetInteger (key) = match getInteger(this, key) { | |
15 | - | case b: Int => | |
16 | - | b | |
17 | - | case _ => | |
18 | - | 0 | |
19 | - | } | |
20 | - | ||
21 | - | ||
22 | - | func calculateCurrentAssetInterest (assetId,assetIdStr) = { | |
23 | - | let totalStaked = tryGetInteger("global_puzzleStaked") | |
24 | - | let tokenBalanceLastCheck = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")) | |
25 | - | let currentTokenEarnings = max([tokenBalanceLastCheck, assetBalance(this, assetId)]) | |
26 | - | let newEarnings = (currentTokenEarnings - tokenBalanceLastCheck) | |
27 | - | let newInterest = if ((totalStaked == 0)) | |
28 | - | then 0 | |
29 | - | else fraction(newEarnings, scale, totalStaked) | |
30 | - | let lastCheckInterest = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_interest")) | |
31 | - | (lastCheckInterest + newInterest) | |
32 | - | } | |
33 | - | ||
34 | - | ||
35 | - | func claimResult (address) = { | |
36 | - | let addressStr = toString(address) | |
37 | - | let puzzleAmount = tryGetInteger((addressStr + "_puzzleStaked")) | |
38 | - | func handler (accum,assetId) = { | |
39 | - | let assetIdStr = toBase58String(assetId) | |
40 | - | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
41 | - | let currentTokenEarnings = max([tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings")), assetBalance(this, assetId)]) | |
42 | - | let rewardAmount = fraction(puzzleAmount, (currentTokenInterest - tryGetInteger((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"))), scale) | |
43 | - | if ((rewardAmount == 0)) | |
44 | - | then accum | |
45 | - | else (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), (currentTokenEarnings - rewardAmount)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest), ScriptTransfer(address, rewardAmount, assetId)]) | |
46 | - | } | |
47 | - | ||
48 | - | let $l = earnedAssets | |
49 | - | let $s = size($l) | |
50 | - | let $acc0 = nil | |
51 | - | func 1 ($a,$i) = if (($i >= $s)) | |
52 | - | then $a | |
53 | - | else handler($a, $l[$i]) | |
54 | - | ||
55 | - | func 2 ($a,$i) = if (($i >= $s)) | |
56 | - | then $a | |
57 | - | else throw("List size exceeds 17") | |
58 | - | ||
59 | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
60 | - | } | |
61 | 4 | ||
62 | 5 | ||
63 | 6 | @Callable(i) | |
64 | - | func stake () = { | |
65 | - | let addressStr = toString(i.caller) | |
66 | - | let pmt = i.payments[0] | |
67 | - | if ((value(pmt.assetId) != puzzleId)) | |
68 | - | then throw("wrong asset attached") | |
69 | - | else { | |
70 | - | func handler (accum,assetId) = { | |
71 | - | let assetIdStr = toBase58String(assetId) | |
72 | - | let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr) | |
73 | - | (accum ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), assetBalance(this, assetId)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest)]) | |
74 | - | } | |
75 | - | ||
76 | - | let li = { | |
77 | - | let $l = earnedAssets | |
78 | - | let $s = size($l) | |
79 | - | let $acc0 = nil | |
80 | - | func 1 ($a,$i) = if (($i >= $s)) | |
81 | - | then $a | |
82 | - | else handler($a, $l[$i]) | |
83 | - | ||
84 | - | func 2 ($a,$i) = if (($i >= $s)) | |
85 | - | then $a | |
86 | - | else throw("List size exceeds 17") | |
87 | - | ||
88 | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17) | |
89 | - | } | |
90 | - | (li ++ [IntegerEntry((addressStr + "_puzzleStaked"), (tryGetInteger((addressStr + "_puzzleStaked")) + pmt.amount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") + pmt.amount))]) | |
91 | - | } | |
7 | + | func swapDataFailOrREAD () = { | |
8 | + | let pubkey = toBase58String(i.caller.bytes) | |
9 | + | let Added = ("Rewards_Of_" + pubkey) | |
10 | + | let extracted = split(Added, "_") | |
11 | + | [StringEntry("pubkey", pubkey), StringEntry("addedpubkey", Added), StringEntry("extracted", extracted[0])] | |
92 | 12 | } | |
93 | - | ||
94 | - | ||
95 | - | ||
96 | - | @Callable(i) | |
97 | - | func unstake (puzzleAmount) = { | |
98 | - | let addressStr = toString(i.caller) | |
99 | - | let puzzleAvailable = tryGetInteger((addressStr + "_puzzleStaked")) | |
100 | - | if ((puzzleAmount > puzzleAvailable)) | |
101 | - | then throw("you don't have PUZZLE available") | |
102 | - | else (claimResult(i.caller) ++ [IntegerEntry((addressStr + "_puzzleStaked"), (puzzleAvailable - puzzleAmount)), IntegerEntry("global_puzzleStaked", (tryGetInteger("global_puzzleStaked") - puzzleAmount))]) | |
103 | - | } | |
104 | - | ||
105 | - | ||
106 | - | ||
107 | - | @Callable(i) | |
108 | - | func claim () = claimResult(i.caller) | |
109 | 13 | ||
110 | 14 | ||
111 | 15 | @Verifier(tx) | |
112 | 16 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
113 | 17 |
github/deemru/w8io/169f3d6 27.63 ms ◑