tx · 3kCNtQWtT1ARCA9qcRJ5NTZXM8Z3DpkSQskbhoNMz4E2 3MqyJd7BQfD1YwGvcQRgtbRsWoEKfHQs6nZ: -0.01000000 Waves 2021.09.08 12:16 [1693878] smart account 3MqyJd7BQfD1YwGvcQRgtbRsWoEKfHQs6nZ > SELF 0.00000000 Waves
{ "type": 13, "id": "3kCNtQWtT1ARCA9qcRJ5NTZXM8Z3DpkSQskbhoNMz4E2", "fee": 1000000, "feeAssetId": null, "timestamp": 1631092672417, "version": 1, "sender": "3MqyJd7BQfD1YwGvcQRgtbRsWoEKfHQs6nZ", "senderPublicKey": "2VDqMFZAWpAysmREhbgRG8bxyYrTWv3gLk4TSAn9zmXr", "proofs": [ "5rs2U8wzxku2YS4fmqff9jFn3XE8LBBYpYRTc3ViXN78f2EQ2g1WCnQRaaZMfqoURhSY1MbRQc9swywcfAMwZVzD" ], "script": "base64:AAIFAAAAAAAAAA8IAhIDCgEIEgASBAoCCAEAAAAMAAAAAANTRVACAAAAAl9fAQAAAA9nZXRTdHJpbmdPckZhaWwAAAABAAAAA2tleQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEIgAAAAEFAAAAA2tleQkAASwAAAACCQABLAAAAAICAAAAD21hbmRhdG9yeSB0aGlzLgUAAAADa2V5AgAAAA8gaXMgbm90IGRlZmluZWQBAAAAGGdldFN0cmluZ0J5QWRkcmVzc09yRmFpbAAAAAIAAAAHYWRkcmVzcwAAAANrZXkJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAdhZGRyZXNzBQAAAANrZXkJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAKbWFuZGF0b3J5IAkABCUAAAABBQAAAAdhZGRyZXNzAgAAAAEuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAARa2V5RmFjdG9yeUFkZHJlc3MAAAAAAgAAABwlcyVzX19jb25maWdfX2ZhY3RvcnlB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ADHN0YWtlZEJ5VXNlcgkAAAIAAAABAgAAACRwYXNzZWQgYW1vdW50IGlzIGxlc3MgdGhlbiBhdmFpbGFibGUJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAAD3N0YWtlZEJ5VXNlcktFWQkAAGUAAAACBQAAAAxzdGFrZWRCeVVzZXIFAAAABmFtb3VudAkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgUAAAAOc3Rha2VkVG90YWxLRVkJAABlAAAAAgUAAAALc3Rha2VkVG90YWwFAAAABmFtb3VudAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAABaQAAAAZjYWxsZXIFAAAABmFtb3VudAUAAAAHYXNzZXRJZAkABEwAAAACCQEAAAAVT3BlcmF0aW9uSGlzdG9yeUVudHJ5AAAABQIAAAAFY2xhaW0FAAAADnVzZXJBZGRyZXNzU3RyBQAAAAphc3NldElkU3RyBQAAAAZhbW91bnQIBQAAAAFpAAAADXRyYW5zYWN0aW9uSWQFAAAAA25pbAAAAABrzkBW", "chainId": 84, "height": 1693878, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let SEP = "__" | |
5 | + | ||
6 | + | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) | |
7 | + | ||
8 | + | ||
9 | + | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
10 | + | ||
11 | + | ||
12 | + | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
13 | + | ||
14 | + | ||
15 | + | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
16 | + | ||
17 | + | ||
18 | + | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) | |
19 | + | ||
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 | + | ||
39 | + | @Callable(i) | |
40 | + | func constructor (factoryAddressStr) = if ((i.caller != this)) | |
41 | + | then throw("not authorized") | |
42 | + | else [StringEntry(keyFactoryAddress(), factoryAddressStr)] | |
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | @Callable(i) | |
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, amount), IntegerEntry(stakedTotalKEY, amount), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
65 | + | } | |
66 | + | } | |
67 | + | } | |
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | @Callable(i) | |
72 | + | func claim (assetIdStr,amount) = { | |
73 | + | let factory = readFactoryAddressOrFail() | |
74 | + | let userAddressStr = toString(i.caller) | |
75 | + | let assetId = fromBase58String(assetIdStr) | |
76 | + | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(assetIdStr))))) | |
77 | + | then throw(("unsupported lp asset " + assetIdStr)) | |
78 | + | else { | |
79 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, assetIdStr) | |
80 | + | let stakedTotalKEY = keyStakedByUser(userAddressStr, assetIdStr) | |
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, assetId), OperationHistoryEntry("claim", userAddressStr, assetIdStr, amount, i.transactionId)] | |
86 | + | } | |
87 | + | } | |
88 | + | ||
89 | + |
github/deemru/w8io/026f985 21.47 ms ◑