tx · FuKAqhWzSzR6W2kR1YWywd3kcH9SiKqzCZVY8jF2bqap 3N5JsQHh6GJBT7gCj8pKKGhfmdVbHUUE7Ra: -0.01400000 Waves 2021.07.22 20:34 [1625157] smart account 3N5JsQHh6GJBT7gCj8pKKGhfmdVbHUUE7Ra > SELF 0.00000000 Waves
{ "type": 13, "id": "FuKAqhWzSzR6W2kR1YWywd3kcH9SiKqzCZVY8jF2bqap", "fee": 1400000, "feeAssetId": null, "timestamp": 1626975092009, "version": 2, "chainId": 84, "sender": "3N5JsQHh6GJBT7gCj8pKKGhfmdVbHUUE7Ra", "senderPublicKey": "6hg3zCfLeDbfSrz2QVG7hdax7eXSpabUDqSP1ya8PBVZ", "proofs": [ "4R3oRPfkC6fzJim2VQGJEoHLt7XLBqGtu6Q4rfjqGwS1naWWQjPKJxt86wWhtc5sj8s1SPH8K9HTZuwoQpurbYEQ" ], "script": "base64:AAIFAAAAAAAAAAcIAhIDCgEBAAAACgAAAAAOZ292ZXJuYW5jZUFkZHIJAQAAAAdBZGRyZXNzAAAAAQEAAAAAAAAAAAtzZXJ2aWNlQWRkcgkBAAAAB0FkZHJlc3MAAAABAQAAAAAAAAAAD2tleUxhc3RJbnRlcmVzdAIAAAANbGFzdF9pbnRlcmVzdAAAAAARa2V5VXNlclNXT1BMb2NrZWQCAAAADF9TV09QX2Ftb3VudAAAAAATa2V5VXNlckxhc3RJbnRlcmVzdAIAAAAOX2xhc3RfaW50ZXJlc3QAAAAACnNjYWxlVmFsdWUAAAAAAAX14QABAAAAE2dldExhc3RJbnRlcmVzdEluZm8AAAAABAAAAAxsYXN0SW50ZXJlc3QJAQAAAAt2YWx1ZU9yRWxzZQAAAAIJAAQaAAAAAgUAAAAOZ292ZXJuYW5jZUFkZHIFAAAAD2tleUxhc3RJbnRlcmVzdAAAAAAAAAAAAAUAAAAMbGFzdEludGVyZXN0AQAAABFnZXRVc2VyU1dPUExvY2tlZAAAAAEAAAAEdXNlcgkBAAAAC3ZhbHVlT3JFb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QAAAApzY2FsZVZhbHVlBAAAAA91c2VyTmV3SW50ZXJlc3QFAAAADGxhc3RJbnRlcmVzdAkABRQAAAACBQAAAA91c2VyTmV3SW50ZXJlc3QFAAAAC2NsYWltQW1vdW50AAAAAQAAAAFpAQAAABFyZXN0YWtlR292ZXJuYW5jZQAAAAEAAAANbWluU1dPUHJld2FyZAMJAQAAAAIhPQAAAAIIBQAAAAFpAAAABmNhbGxlcgUAAAALc2VydmljZUFkZHIJAAACAAAAAQIAAAAxT25seSBzdGFraW5nIHNlcnZpY2UgaXMgYWxsb3dlZCB0byBjYWxsIHRoaXMgZnVuYwQAAAALY2xhaW1BbW91bnQICQEAAAAJY2xhaW1DYWxjAAAAAQUAAAAEdGhpcwAAAAJfMgMJAABmAAAAAgUAAAANbWluU1dPUHJld2FyZAUAAAALY2xhaW1BbW91bnQJAAACAAAAAQIAAAAqQW1vdW50IHRvIGNsYWltIGlzIGxlc3MgdGhhbiBtaW5TV09QcmV3YXJkBAAAAAF6CQAD/AAAAAQFAAAADmdvdmVybmFuY2VBZGRyAgAAABFjbGFpbUFuZFN0YWtlU1dPUAUAAAADbmlsBQAAAANuaWwDCQAAAAAAAAIFAAAAAXoFAAAAAXoFAAAAA25pbAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tlecbFJzg=", "height": 1625157, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BLMP5ftxN92eJxKwSMCwNBp8oaY1Pd5Bairfs5X7KcF9 Next: 62sxiBmiAEbo46GqRg9LN6tzRexgNSXc8UZi3zkNMKSQ Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let governanceAddr = Address(base58'') | |
5 | 5 | ||
6 | - | let | |
6 | + | let serviceAddr = Address(base58'') | |
7 | 7 | ||
8 | - | let | |
8 | + | let keyLastInterest = "last_interest" | |
9 | 9 | ||
10 | - | let | |
10 | + | let keyUserSWOPLocked = "_SWOP_amount" | |
11 | 11 | ||
12 | - | let | |
12 | + | let keyUserLastInterest = "_last_interest" | |
13 | 13 | ||
14 | - | let | |
14 | + | let scaleValue = 100000000 | |
15 | 15 | ||
16 | - | let kCloseTxId = "_close_tx_id" | |
17 | - | ||
18 | - | let statusActive = "Active" | |
19 | - | ||
20 | - | let statusCanceled = "Canceled" | |
21 | - | ||
22 | - | let statusDone = "Done" | |
23 | - | ||
24 | - | @Callable(i) | |
25 | - | func placeProposal (desireToGetAssetId,desireToGetAmount) = { | |
26 | - | let $t0525624 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
27 | - | let pmtAmount = $t0525624._1 | |
28 | - | let pmtAssetId = $t0525624._2 | |
29 | - | let id = toBase58String(i.transactionId) | |
30 | - | [StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), StringEntry((id + kStatus), statusActive)] | |
16 | + | func getLastInterestInfo () = { | |
17 | + | let lastInterest = valueOrElse(getInteger(governanceAddr, keyLastInterest), 0) | |
18 | + | lastInterest | |
31 | 19 | } | |
32 | 20 | ||
33 | 21 | ||
22 | + | func getUserSWOPLocked (user) = valueOrElse(getInteger(governanceAddr, (toString(user) + keyUserSWOPLocked)), 0) | |
34 | 23 | ||
35 | - | @Callable(i) | |
36 | - | func cancelProposal (id) = { | |
37 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
38 | - | if ((status != statusActive)) | |
39 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
40 | - | else { | |
41 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
42 | - | let proposedAssetId = valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found") | |
43 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
44 | - | if ((i.caller != ownerAddr)) | |
45 | - | then throw("Only owner can cancel") | |
46 | - | else [ScriptTransfer(ownerAddr, proposedAssetAmount, fromBase58String(proposedAssetId)), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
47 | - | } | |
24 | + | ||
25 | + | func getUserInterestInfo (user,lastInterest) = { | |
26 | + | let userSWOPAmount = getUserSWOPLocked(user) | |
27 | + | let userLastInterest = getInteger(governanceAddr, (toString(user) + keyUserLastInterest)) | |
28 | + | let userLastInterestValue = match userLastInterest { | |
29 | + | case userLastInterest: Int => | |
30 | + | userLastInterest | |
31 | + | case _ => | |
32 | + | lastInterest | |
33 | + | } | |
34 | + | $Tuple2(userLastInterestValue, userSWOPAmount) | |
48 | 35 | } | |
49 | 36 | ||
50 | 37 | ||
38 | + | func claimCalc (caller) = { | |
39 | + | let lastInterest = getLastInterestInfo() | |
40 | + | let uifo = getUserInterestInfo(caller, lastInterest) | |
41 | + | let userLastInterest = uifo._1 | |
42 | + | let userSWOPLocked = uifo._2 | |
43 | + | let claimAmount = fraction(userSWOPLocked, (lastInterest - userLastInterest), scaleValue) | |
44 | + | let userNewInterest = lastInterest | |
45 | + | $Tuple2(userNewInterest, claimAmount) | |
46 | + | } | |
47 | + | ||
51 | 48 | ||
52 | 49 | @Callable(i) | |
53 | - | func acceptProposal (id) = { | |
54 | - | let $t019442027 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
55 | - | let pmtAmount = $t019442027._1 | |
56 | - | let pmtAssetId = $t019442027._2 | |
57 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
58 | - | if ((status != statusActive)) | |
59 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
60 | - | else { | |
61 | - | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
62 | - | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
63 | - | if ((desiredAssetId != pmtAssetId)) | |
64 | - | then throw("Atatched asset doesn't match desired") | |
65 | - | else if ((desiredAssetAmount != pmtAmount)) | |
66 | - | then throw("Attached asset amount doesn't match") | |
67 | - | else { | |
68 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
69 | - | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
70 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
71 | - | [ScriptTransfer(ownerAddr, desiredAssetAmount, desiredAssetId), ScriptTransfer(i.caller, proposedAssetAmount, proposedAssetId), StringEntry((id + kStatus), statusDone), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
72 | - | } | |
73 | - | } | |
74 | - | } | |
50 | + | func restakeGovernance (minSWOPreward) = if ((i.caller != serviceAddr)) | |
51 | + | then throw("Only staking service is allowed to call this func") | |
52 | + | else { | |
53 | + | let claimAmount = claimCalc(this)._2 | |
54 | + | if ((minSWOPreward > claimAmount)) | |
55 | + | then throw("Amount to claim is less than minSWOPreward") | |
56 | + | else { | |
57 | + | let z = invoke(governanceAddr, "claimAndStakeSWOP", nil, nil) | |
58 | + | if ((z == z)) | |
59 | + | then nil | |
60 | + | else throw("Strict value is not equal to itself.") | |
61 | + | } | |
62 | + | } | |
75 | 63 | ||
76 | 64 | ||
77 | 65 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let governanceAddr = Address(base58'') | |
5 | 5 | ||
6 | - | let | |
6 | + | let serviceAddr = Address(base58'') | |
7 | 7 | ||
8 | - | let | |
8 | + | let keyLastInterest = "last_interest" | |
9 | 9 | ||
10 | - | let | |
10 | + | let keyUserSWOPLocked = "_SWOP_amount" | |
11 | 11 | ||
12 | - | let | |
12 | + | let keyUserLastInterest = "_last_interest" | |
13 | 13 | ||
14 | - | let | |
14 | + | let scaleValue = 100000000 | |
15 | 15 | ||
16 | - | let kCloseTxId = "_close_tx_id" | |
17 | - | ||
18 | - | let statusActive = "Active" | |
19 | - | ||
20 | - | let statusCanceled = "Canceled" | |
21 | - | ||
22 | - | let statusDone = "Done" | |
23 | - | ||
24 | - | @Callable(i) | |
25 | - | func placeProposal (desireToGetAssetId,desireToGetAmount) = { | |
26 | - | let $t0525624 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
27 | - | let pmtAmount = $t0525624._1 | |
28 | - | let pmtAssetId = $t0525624._2 | |
29 | - | let id = toBase58String(i.transactionId) | |
30 | - | [StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), StringEntry((id + kStatus), statusActive)] | |
16 | + | func getLastInterestInfo () = { | |
17 | + | let lastInterest = valueOrElse(getInteger(governanceAddr, keyLastInterest), 0) | |
18 | + | lastInterest | |
31 | 19 | } | |
32 | 20 | ||
33 | 21 | ||
22 | + | func getUserSWOPLocked (user) = valueOrElse(getInteger(governanceAddr, (toString(user) + keyUserSWOPLocked)), 0) | |
34 | 23 | ||
35 | - | @Callable(i) | |
36 | - | func cancelProposal (id) = { | |
37 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
38 | - | if ((status != statusActive)) | |
39 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
40 | - | else { | |
41 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
42 | - | let proposedAssetId = valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found") | |
43 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
44 | - | if ((i.caller != ownerAddr)) | |
45 | - | then throw("Only owner can cancel") | |
46 | - | else [ScriptTransfer(ownerAddr, proposedAssetAmount, fromBase58String(proposedAssetId)), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
47 | - | } | |
24 | + | ||
25 | + | func getUserInterestInfo (user,lastInterest) = { | |
26 | + | let userSWOPAmount = getUserSWOPLocked(user) | |
27 | + | let userLastInterest = getInteger(governanceAddr, (toString(user) + keyUserLastInterest)) | |
28 | + | let userLastInterestValue = match userLastInterest { | |
29 | + | case userLastInterest: Int => | |
30 | + | userLastInterest | |
31 | + | case _ => | |
32 | + | lastInterest | |
33 | + | } | |
34 | + | $Tuple2(userLastInterestValue, userSWOPAmount) | |
48 | 35 | } | |
49 | 36 | ||
50 | 37 | ||
38 | + | func claimCalc (caller) = { | |
39 | + | let lastInterest = getLastInterestInfo() | |
40 | + | let uifo = getUserInterestInfo(caller, lastInterest) | |
41 | + | let userLastInterest = uifo._1 | |
42 | + | let userSWOPLocked = uifo._2 | |
43 | + | let claimAmount = fraction(userSWOPLocked, (lastInterest - userLastInterest), scaleValue) | |
44 | + | let userNewInterest = lastInterest | |
45 | + | $Tuple2(userNewInterest, claimAmount) | |
46 | + | } | |
47 | + | ||
51 | 48 | ||
52 | 49 | @Callable(i) | |
53 | - | func acceptProposal (id) = { | |
54 | - | let $t019442027 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
55 | - | let pmtAmount = $t019442027._1 | |
56 | - | let pmtAssetId = $t019442027._2 | |
57 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
58 | - | if ((status != statusActive)) | |
59 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
60 | - | else { | |
61 | - | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
62 | - | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
63 | - | if ((desiredAssetId != pmtAssetId)) | |
64 | - | then throw("Atatched asset doesn't match desired") | |
65 | - | else if ((desiredAssetAmount != pmtAmount)) | |
66 | - | then throw("Attached asset amount doesn't match") | |
67 | - | else { | |
68 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
69 | - | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
70 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
71 | - | [ScriptTransfer(ownerAddr, desiredAssetAmount, desiredAssetId), ScriptTransfer(i.caller, proposedAssetAmount, proposedAssetId), StringEntry((id + kStatus), statusDone), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
72 | - | } | |
73 | - | } | |
74 | - | } | |
50 | + | func restakeGovernance (minSWOPreward) = if ((i.caller != serviceAddr)) | |
51 | + | then throw("Only staking service is allowed to call this func") | |
52 | + | else { | |
53 | + | let claimAmount = claimCalc(this)._2 | |
54 | + | if ((minSWOPreward > claimAmount)) | |
55 | + | then throw("Amount to claim is less than minSWOPreward") | |
56 | + | else { | |
57 | + | let z = invoke(governanceAddr, "claimAndStakeSWOP", nil, nil) | |
58 | + | if ((z == z)) | |
59 | + | then nil | |
60 | + | else throw("Strict value is not equal to itself.") | |
61 | + | } | |
62 | + | } | |
75 | 63 | ||
76 | 64 | ||
77 | 65 | @Verifier(tx) | |
78 | 66 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
79 | 67 |
github/deemru/w8io/169f3d6 44.22 ms ◑