tx · 2WQtyHdb3t42PgDjS3Fbr5H69a67eFqjByxGXdgg42cx 3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g: -0.01000000 Waves 2021.09.09 15:32 [1695519] smart account 3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g > SELF 0.00000000 Waves
{ "type": 13, "id": "2WQtyHdb3t42PgDjS3Fbr5H69a67eFqjByxGXdgg42cx", "fee": 1000000, "feeAssetId": null, "timestamp": 1631190737978, "version": 1, "sender": "3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g", "senderPublicKey": "AkPpYa8oqgaNXjTSuWGaMCnJ6y44pYUMeskeBjzVgPhr", "proofs": [ "2K1m3wiRi32fUxHnjLyp9GBeE91UkK4UsziF222pMALPtYSBmMUZooScLgneiD5PzBdMi1MMa8DEkLYC6aVDG27v" ], "script": "base64:AAIFAAAAAAAAABoIAhIDCgEIEgASBAoCCAESAwoBCBIECgIICAAAAAwAAAAAA1NFUAIAAAACX18BAAAAD2dldFN0cmluZ09yRmFpbAAAAAEAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQiAAAAAQUAAAADa2V5CQABLAAAAAIJAAEsAAAAAgIAAAAPbWFuZGF0b3J5IHRoaXMuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAAYZ2V0U3RyaW5nQnlBZGRyZXNzT3JGYWlsAAAAAgAAAAdhZGRyZXNzAAAAA2tleQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAAB2FkZHJlc3MFAAAAA2tleQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAptYW5kYXRvcnkgCQAEJQAAAAEFAAAAB2FkZHJlc3MCAAAAAS4FAAAAA2tleQIAAAAPIGlzIG5vdCBkZWZpbmVkAQAAABFrZXlGYWN0b3J5QWRkcmVzcwAAAAACAAAAHCVzJXNfX2NvbmZpZ19fZmFjdG9yeUF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3RhbAkBAAAACnJlYWRTdGFrZWQAAAABBQAAAA5zdGFrZWRUb3RhbEtFWQMJAABmAAAAAgUAAAAGYW1vdW50BQAAAAxzdGFrZWRCeVVzZXIJAAACAAAAAQIAAAAkcGFzc2VkIGFtb3VudCBpcyBsZXNzIHRoZW4gYXZhaWxhYmxlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAA9zdGFrZWRCeVVzZXJLRVkJAABlAAAAAgUAAAAMc3Rha2VkQnlVc2VyBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAADnN0YWtlZFRvdGFsS0VZCQAAZQAAAAIFAAAAC3N0YWtlZFRvdGFsBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAACWxwQXNzZXRJZAkABEwAAAACCQEAAAAVT3BlcmF0aW9uSGlzdG9yeUVudHJ5AAAABQIAAAAHdW5zdGFrZQUAAAAOdXNlckFkZHJlc3NTdHIFAAAADGxwQXNzZXRJZFN0cgUAAAAGYW1vdW50CAUAAAABaQAAAA10cmFuc2FjdGlvbklkBQAAAANuaWwAAAABaQEAAAAHY2xhaW1XeAAAAAEAAAAMbHBBc3NldElkU3RyCQAAAgAAAAECAAAAEXRlbW9yYXJ5IGRpc2FibGVkAAAAAWkBAAAAD2NsYWltV3hSRUFET05MWQAAAAIAAAAMbHBBc3NldElkU3RyAAAAC3VzZXJBZGRyZXNzCQAFFAAAAAIFAAAAA25pbAkABLkAAAACCQAETAAAAAICAAAABiVzJXMlZAkABEwAAAACBQAAAAxscEFzc2V0SWRTdHIJAARMAAAAAgUAAAALdXNlckFkZHJlc3MJAARMAAAAAgIAAAALMTAwMDA1MDAwMDAFAAAAA25pbAUAAAADU0VQAAAAACLJ00s=", "chainId": 84, "height": 1695519, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8K418caAMrRd84nhmSZv8UCULSV4qQ9XkwT3hC5XyZ29 Next: 49RkKxfBWBsZMt8LudpTrDkbmKn4sfFeN9JDu28niPEi Diff:
Old | New | Differences | |
---|---|---|---|
18 | 18 | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) | |
19 | 19 | ||
20 | 20 | ||
21 | + | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) | |
22 | + | ||
23 | + | ||
24 | + | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) | |
25 | + | ||
26 | + | ||
27 | + | func readStaked (key) = valueOrElse(getInteger(this, key), 0) | |
28 | + | ||
29 | + | ||
30 | + | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) | |
31 | + | ||
32 | + | ||
33 | + | func formatHistoryRecord (userAddress,lpAssetId,type,amount) = makeString(["%s%s%s%d%d%d", userAddress, lpAssetId, type, toString(height), toString(lastBlock.timestamp), toString(amount)], SEP) | |
34 | + | ||
35 | + | ||
36 | + | func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount)) | |
37 | + | ||
38 | + | ||
21 | 39 | @Callable(i) | |
22 | - | func constructor ( | |
40 | + | func constructor (factoryAddressStr) = if ((i.caller != this)) | |
23 | 41 | then throw("not authorized") | |
24 | - | else [StringEntry(keyFactoryAddress(), | |
42 | + | else [StringEntry(keyFactoryAddress(), factoryAddressStr)] | |
25 | 43 | ||
26 | 44 | ||
27 | 45 | ||
28 | 46 | @Callable(i) | |
29 | - | func currentRewardRateREADONLY (lpAssetId) = $Tuple2(nil, makeString(["%d%d%d", "320000000", "1100000000", "100000000000"], SEP)) | |
47 | + | func stake () = { | |
48 | + | let factory = readFactoryAddressOrFail() | |
49 | + | if ((size(i.payments) != 1)) | |
50 | + | then throw("invalid payment - exact one payment must be attached") | |
51 | + | else { | |
52 | + | let pmt = i.payments[0] | |
53 | + | let lpAssetId = value(pmt.assetId) | |
54 | + | let lpAssetIdStr = toBase58String(lpAssetId) | |
55 | + | let userAddressStr = toString(i.caller) | |
56 | + | let amount = pmt.amount | |
57 | + | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
58 | + | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
59 | + | else { | |
60 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
61 | + | let stakedTotalKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
62 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
63 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
64 | + | [IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
65 | + | } | |
66 | + | } | |
67 | + | } | |
30 | 68 | ||
31 | 69 | ||
32 | 70 | ||
33 | 71 | @Callable(i) | |
34 | - | func currentUserRewardRateREADONLY (lpAssetId,userAddress) = $Tuple2(nil, makeString(["%d%d%d", "320000000", "1100000000", "100000000000", "1000000000", "100000000"], SEP)) | |
72 | + | func unstake (lpAssetIdStr,amount) = { | |
73 | + | let factory = readFactoryAddressOrFail() | |
74 | + | let userAddressStr = toString(i.caller) | |
75 | + | let lpAssetId = fromBase58String(lpAssetIdStr) | |
76 | + | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
77 | + | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
78 | + | else { | |
79 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
80 | + | let stakedTotalKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
81 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
82 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
83 | + | if ((amount > stakedByUser)) | |
84 | + | then throw("passed amount is less then available") | |
85 | + | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
86 | + | } | |
87 | + | } | |
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | @Callable(i) | |
92 | + | func claimWx (lpAssetIdStr) = throw("temorary disabled") | |
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | @Callable(i) | |
97 | + | func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "10000500000"], SEP)) | |
35 | 98 | ||
36 | 99 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) | |
19 | 19 | ||
20 | 20 | ||
21 | + | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) | |
22 | + | ||
23 | + | ||
24 | + | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) | |
25 | + | ||
26 | + | ||
27 | + | func readStaked (key) = valueOrElse(getInteger(this, key), 0) | |
28 | + | ||
29 | + | ||
30 | + | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) | |
31 | + | ||
32 | + | ||
33 | + | func formatHistoryRecord (userAddress,lpAssetId,type,amount) = makeString(["%s%s%s%d%d%d", userAddress, lpAssetId, type, toString(height), toString(lastBlock.timestamp), toString(amount)], SEP) | |
34 | + | ||
35 | + | ||
36 | + | func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount)) | |
37 | + | ||
38 | + | ||
21 | 39 | @Callable(i) | |
22 | - | func constructor ( | |
40 | + | func constructor (factoryAddressStr) = if ((i.caller != this)) | |
23 | 41 | then throw("not authorized") | |
24 | - | else [StringEntry(keyFactoryAddress(), | |
42 | + | else [StringEntry(keyFactoryAddress(), factoryAddressStr)] | |
25 | 43 | ||
26 | 44 | ||
27 | 45 | ||
28 | 46 | @Callable(i) | |
29 | - | func currentRewardRateREADONLY (lpAssetId) = $Tuple2(nil, makeString(["%d%d%d", "320000000", "1100000000", "100000000000"], SEP)) | |
47 | + | func stake () = { | |
48 | + | let factory = readFactoryAddressOrFail() | |
49 | + | if ((size(i.payments) != 1)) | |
50 | + | then throw("invalid payment - exact one payment must be attached") | |
51 | + | else { | |
52 | + | let pmt = i.payments[0] | |
53 | + | let lpAssetId = value(pmt.assetId) | |
54 | + | let lpAssetIdStr = toBase58String(lpAssetId) | |
55 | + | let userAddressStr = toString(i.caller) | |
56 | + | let amount = pmt.amount | |
57 | + | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
58 | + | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
59 | + | else { | |
60 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
61 | + | let stakedTotalKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
62 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
63 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
64 | + | [IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
65 | + | } | |
66 | + | } | |
67 | + | } | |
30 | 68 | ||
31 | 69 | ||
32 | 70 | ||
33 | 71 | @Callable(i) | |
34 | - | func currentUserRewardRateREADONLY (lpAssetId,userAddress) = $Tuple2(nil, makeString(["%d%d%d", "320000000", "1100000000", "100000000000", "1000000000", "100000000"], SEP)) | |
72 | + | func unstake (lpAssetIdStr,amount) = { | |
73 | + | let factory = readFactoryAddressOrFail() | |
74 | + | let userAddressStr = toString(i.caller) | |
75 | + | let lpAssetId = fromBase58String(lpAssetIdStr) | |
76 | + | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
77 | + | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
78 | + | else { | |
79 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
80 | + | let stakedTotalKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
81 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
82 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
83 | + | if ((amount > stakedByUser)) | |
84 | + | then throw("passed amount is less then available") | |
85 | + | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
86 | + | } | |
87 | + | } | |
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | @Callable(i) | |
92 | + | func claimWx (lpAssetIdStr) = throw("temorary disabled") | |
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | @Callable(i) | |
97 | + | func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "10000500000"], SEP)) | |
35 | 98 | ||
36 | 99 |
github/deemru/w8io/169f3d6 25.61 ms ◑