tx · 4yXNVTb9Pk8wjQQFuweY7GGJUjdDajMYDUDFoxjSsdQy 3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g: -0.01000000 Waves 2021.09.08 12:28 [1693891] smart account 3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g > SELF 0.00000000 Waves
{ "type": 13, "id": "4yXNVTb9Pk8wjQQFuweY7GGJUjdDajMYDUDFoxjSsdQy", "fee": 1000000, "feeAssetId": null, "timestamp": 1631093389706, "version": 1, "sender": "3N6DGohy3A1oqkBk6F4BRPHrqgkVgwxWd8g", "senderPublicKey": "AkPpYa8oqgaNXjTSuWGaMCnJ6y44pYUMeskeBjzVgPhr", "proofs": [ "5GjPikA8yreyXR6nsy17cqL3n3J6EXbbtS7ZMFheT4UbEm9SV6WmACxyXCUkTrkeb7eZP6mD9ymC5KsQiNqua1XL" ], "script": "base64:AAIFAAAAAAAAAA8IAhIDCgEIEgASBAoCCAEAAAAMAAAAAANTRVACAAAAAl9fAQAAAA9nZXRTdHJpbmdPckZhaWwAAAABAAAAA2tleQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEIgAAAAEFAAAAA2tleQkAASwAAAACCQABLAAAAAICAAAAD21hbmRhdG9yeSB0aGlzLgUAAAADa2V5AgAAAA8gaXMgbm90IGRlZmluZWQBAAAAGGdldFN0cmluZ0J5QWRkcmVzc09yRmFpbAAAAAIAAAAHYWRkcmVzcwAAAANrZXkJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAdhZGRyZXNzBQAAAANrZXkJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAKbWFuZGF0b3J5IAkABCUAAAABBQAAAAdhZGRyZXNzAgAAAAEuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAARa2V5RmFjdG9yeUFkZHJlc3MAAAAAAgAAABwlcyVzX19jb25maWdfX2ZhY3RvcnlBZGRyZXNzA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WRUb3RhbEtFWQMJAABmAAAAAgUAAAAGYW1vdW50BQAAAAxzdGFrZWRCeVVzZXIJAAACAAAAAQIAAAAkcGFzc2VkIGFtb3VudCBpcyBsZXNzIHRoZW4gYXZhaWxhYmxlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAA9zdGFrZWRCeVVzZXJLRVkJAABlAAAAAgUAAAAMc3Rha2VkQnlVc2VyBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAADnN0YWtlZFRvdGFsS0VZCQAAZQAAAAIFAAAAC3N0YWtlZFRvdGFsBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAAB2Fzc2V0SWQJAARMAAAAAgkBAAAAFU9wZXJhdGlvbkhpc3RvcnlFbnRyeQAAAAUCAAAABWNsYWltBQAAAA51c2VyQWRkcmVzc1N0cgUAAAAKYXNzZXRJZFN0cgUAAAAGYW1vdW50CAUAAAABaQAAAA10cmFuc2FjdGlvbklkBQAAAANuaWwAAAAAdndHyg==", "chainId": 84, "height": 1693891, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 2X34MQo4U98fTXgvBRU4MAP4RsESyBvnvXrU6eWY9avC Next: 8bEW6uZ6vPS8ahgjr7nNDVCZmQXAAabV9tHCb2dHTXZN Full:
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 | 21 | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func readStaked (key) = valueOrElse(getInteger(this, key), 0) | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) | |
31 | 31 | ||
32 | 32 | ||
33 | 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 | 34 | ||
35 | 35 | ||
36 | 36 | func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount)) | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | @Callable(i) | |
40 | 40 | func constructor (factoryAddressStr) = if ((i.caller != this)) | |
41 | 41 | then throw("not authorized") | |
42 | 42 | else [StringEntry(keyFactoryAddress(), factoryAddressStr)] | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | ||
46 | 46 | @Callable(i) | |
47 | 47 | func stake () = { | |
48 | 48 | let factory = readFactoryAddressOrFail() | |
49 | 49 | if ((size(i.payments) != 1)) | |
50 | 50 | then throw("invalid payment - exact one payment must be attached") | |
51 | 51 | else { | |
52 | 52 | let pmt = i.payments[0] | |
53 | 53 | let lpAssetId = value(pmt.assetId) | |
54 | 54 | let lpAssetIdStr = toBase58String(lpAssetId) | |
55 | 55 | let userAddressStr = toString(i.caller) | |
56 | 56 | let amount = pmt.amount | |
57 | 57 | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
58 | 58 | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
59 | 59 | else { | |
60 | 60 | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
61 | 61 | let stakedTotalKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
62 | 62 | let stakedByUser = readStaked(stakedByUserKEY) | |
63 | 63 | let stakedTotal = readStaked(stakedTotalKEY) | |
64 | 64 | [IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
65 | 65 | } | |
66 | 66 | } | |
67 | 67 | } | |
68 | 68 | ||
69 | 69 | ||
70 | 70 | ||
71 | 71 | @Callable(i) | |
72 | 72 | func claim (assetIdStr,amount) = { | |
73 | 73 | let factory = readFactoryAddressOrFail() | |
74 | 74 | let userAddressStr = toString(i.caller) | |
75 | 75 | let assetId = fromBase58String(assetIdStr) | |
76 | 76 | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(assetIdStr))))) | |
77 | 77 | then throw(("unsupported lp asset " + assetIdStr)) | |
78 | 78 | else { | |
79 | 79 | let stakedByUserKEY = keyStakedByUser(userAddressStr, assetIdStr) | |
80 | 80 | let stakedTotalKEY = keyStakedByUser(userAddressStr, assetIdStr) | |
81 | 81 | let stakedByUser = readStaked(stakedByUserKEY) | |
82 | 82 | let stakedTotal = readStaked(stakedTotalKEY) | |
83 | 83 | if ((amount > stakedByUser)) | |
84 | 84 | then throw("passed amount is less then available") | |
85 | 85 | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, assetId), OperationHistoryEntry("claim", userAddressStr, assetIdStr, amount, i.transactionId)] | |
86 | 86 | } | |
87 | 87 | } | |
88 | 88 | ||
89 | 89 |
github/deemru/w8io/169f3d6 47.76 ms ◑