tx · 3FE8GNfALMnkRNvManK7bfR7TRCJ5p4HqUwPT98Xpm4V 3MwyBKGZcdChEK9Z55HwLn3A2EgwEJJpqC1: -0.01000000 Waves 2024.01.09 13:28 [2923821] smart account 3MwyBKGZcdChEK9Z55HwLn3A2EgwEJJpqC1 > SELF 0.00000000 Waves
{ "type": 13, "id": "3FE8GNfALMnkRNvManK7bfR7TRCJ5p4HqUwPT98Xpm4V", "fee": 1000000, "feeAssetId": null, "timestamp": 1704796126517, "version": 2, "chainId": 84, "sender": "3MwyBKGZcdChEK9Z55HwLn3A2EgwEJJpqC1", "senderPublicKey": "7c3qLtcJ7EaPS2JDjXv8MBbd4kpyc6R27wcn5GgvZhur", "proofs": [ "3b5D7GEchf19m4nKrszjPqe697Tc2EwHcQsMKNPHCmVwsByvtMkhfcq1YHurucCPsJU7ERJ2yffHaHMxPsb5a9w2" ], "script": "base64:BgIKCAISBgoECAEBARIADGNvbnRyYWN0RmlsZQIQdmVzdGluZ19uZW8ucmlkZQADU0VQAgJfXwAISURTX0xJU1QJAMwIAgAACQDMCAIAAQkAzAgCAAIJAMwIAgADCQDMCAIABAkAzAgCAAUJAMwIAgAGCQDMCAIABwkAzAgCAAgJAMwIAgAJCQDMCAIACgkAzAgCAAsJAMwIAgAMCQDMCAIADQkAzAgCAA4JAMwIAgAPCQDMCAIAEAkAzAgCABEJAMwIAgASCQDMCAIAEwkAzAgCABQJAMwIAgAVCQDMCAIAFgkAzAgCABcJAMwIAgAYCQDMCAIAGQkAzAgCABoJAMwIAgAbCQDMCAIAHAkAzAgCAB0FA25pbAARTUFYX1ZFU1RJTkdfQ09VTlQJAJADAQUISURTX0xJU1QBCHRocm93RXJyAQNtc2cJAAIBCQCsAgIJAKwCAgUMY29udHJhY3RGaWxlAgI6IAUDbXNnAAprZXlBc3NldElkCQC5CQIJAMwIAgICJXMJAMwIAgIHYXNzZXRJZAUDbmlsBQNTRVAADWFzc2V0SWRTdHJpbmcJAQt2YWx1ZU9yRWxzZQIJAJ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FAiRhCQACAQIUTGlzdCBzaXplIGV4Y2VlZHMgMzAJAQUkZjBfMgIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIFBSRhY2MwAAAAAQACAAMABAAFAAYABwAIAAkACgALAAwADQAOAA8AEAARABIAEwAUABUAFgAXABgAGQAaABsAHAAdAB4DCQAAAgULYXZhaWxhYmxlSWQA////////////AQkBCHRocm93RXJyAQkAuQkCCQDMCAICIXVzZXIgZXhjZWVkZWQgbWF4IHZlc3RpbmcgY291bnQ6IAkAzAgCBQt1c2VyQWRkcmVzcwUDbmlsAgEgBQthdmFpbGFibGVJZAEBaQEDZm9vBAt1c2VyQWRkcmVzcw12ZXN0aW5nQW1vdW50CnN0YXJ0QmxvY2sKbG9ja0xlbmd0aAkBFGdldE5ld1Zlc3RpbmdBY3Rpb25zBQULdXNlckFkZHJlc3MAAAUNdmVzdGluZ0Ftb3VudAUKc3RhcnRCbG9jawUKbG9ja0xlbmd0aADoaEJU", "height": 2923821, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BBfsqXChmaALfz18pQ658VAcW6EbDY9dAQZQ1oKqVR13 Next: DCzxdEPqxeSrLMoAk5U4Ri7TyfJ5GVMfSFK9gFw28sid Diff:
Old | New | Differences | |
---|---|---|---|
127 | 127 | } | |
128 | 128 | ||
129 | 129 | ||
130 | - | func getAvailableId (userAddress) = nil | |
130 | + | func getAvailableVestingId (userAddress) = { | |
131 | + | func helper (availableId,id) = { | |
132 | + | let $t037583837 = parseUserVesting(userAddress, id) | |
133 | + | let vestingAmount = $t037583837._1 | |
134 | + | let startBlock = $t037583837._2 | |
135 | + | let lockLength = $t037583837._3 | |
136 | + | if ((vestingAmount > 0)) | |
137 | + | then availableId | |
138 | + | else if ((availableId == -1)) | |
139 | + | then id | |
140 | + | else min([availableId, id]) | |
141 | + | } | |
142 | + | ||
143 | + | let availableId = { | |
144 | + | let $l = IDS_LIST | |
145 | + | let $s = size($l) | |
146 | + | let $acc0 = -1 | |
147 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
148 | + | then $a | |
149 | + | else helper($a, $l[$i]) | |
150 | + | ||
151 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
152 | + | then $a | |
153 | + | else throw("List size exceeds 30") | |
154 | + | ||
155 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30) | |
156 | + | } | |
157 | + | if ((availableId == -1)) | |
158 | + | then throwErr(makeString(["user exceeded max vesting count: ", userAddress], " ")) | |
159 | + | else availableId | |
160 | + | } | |
131 | 161 | ||
132 | 162 | ||
133 | 163 | @Callable(i) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let contractFile = "vesting_neo.ride" | |
5 | 5 | ||
6 | 6 | let SEP = "__" | |
7 | 7 | ||
8 | 8 | let IDS_LIST = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] | |
9 | 9 | ||
10 | 10 | let MAX_VESTING_COUNT = size(IDS_LIST) | |
11 | 11 | ||
12 | 12 | func throwErr (msg) = throw(((contractFile + ": ") + msg)) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | let keyAssetId = makeString(["%s", "assetId"], SEP) | |
16 | 16 | ||
17 | 17 | let assetIdString = valueOrElse(getString(this, keyAssetId), "WAVES") | |
18 | 18 | ||
19 | 19 | let assetIdBytes = if ((assetIdString == "WAVES")) | |
20 | 20 | then unit | |
21 | 21 | else fromBase58String(assetIdString) | |
22 | 22 | ||
23 | 23 | func isValidAddressString (addressString) = match addressFromString(addressString) { | |
24 | 24 | case a: Address => | |
25 | 25 | true | |
26 | 26 | case _ => | |
27 | 27 | false | |
28 | 28 | } | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func keyUserVesting (userAddress,id) = { | |
32 | 32 | let checks = [if (isValidAddressString(userAddress)) | |
33 | 33 | then true | |
34 | 34 | else throwErr(makeString(["address is not valid:", userAddress], " ")), if (if ((id >= 0)) | |
35 | 35 | then (MAX_VESTING_COUNT > id) | |
36 | 36 | else false) | |
37 | 37 | then true | |
38 | 38 | else throwErr(makeString(["id should be less than", toString(MAX_VESTING_COUNT), "got:", toString(id)], " "))] | |
39 | 39 | if ((checks == checks)) | |
40 | 40 | then makeString(["%s%d", userAddress, toString(id)], SEP) | |
41 | 41 | else throw("Strict value is not equal to itself.") | |
42 | 42 | } | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func formatUserVesting (vestingAmount,startBlock,lockLength) = { | |
46 | 46 | let checks = [if ((vestingAmount >= 0)) | |
47 | 47 | then true | |
48 | 48 | else throwErr("vesting amount cannot be negative"), if ((startBlock >= 0)) | |
49 | 49 | then true | |
50 | 50 | else throwErr("start block cannot be negative"), if ((lockLength >= 0)) | |
51 | 51 | then true | |
52 | 52 | else throwErr("lock length cannot be negative")] | |
53 | 53 | if ((checks == checks)) | |
54 | 54 | then makeString(["%d%d%d", toString(vestingAmount), toString(startBlock), toString(lockLength)], SEP) | |
55 | 55 | else throw("Strict value is not equal to itself.") | |
56 | 56 | } | |
57 | 57 | ||
58 | 58 | ||
59 | 59 | func parseUserVesting (userAddress,id) = match getString(this, keyUserVesting(userAddress, id)) { | |
60 | 60 | case rawString: String => | |
61 | 61 | let splitString = split(rawString, SEP) | |
62 | 62 | let vestingAmount = parseIntValue(splitString[1]) | |
63 | 63 | let startBlock = parseIntValue(splitString[2]) | |
64 | 64 | let lockLength = parseIntValue(splitString[3]) | |
65 | 65 | $Tuple3(vestingAmount, startBlock, lockLength) | |
66 | 66 | case _ => | |
67 | 67 | $Tuple3(0, 0, 0) | |
68 | 68 | } | |
69 | 69 | ||
70 | 70 | ||
71 | 71 | func calcUnlockedAmount (amount,startBlock,lockLength) = { | |
72 | 72 | let elapsedBlocks = (height - startBlock) | |
73 | 73 | let unlockedAmount = if (if ((lockLength != 0)) | |
74 | 74 | then (elapsedBlocks > 0) | |
75 | 75 | else false) | |
76 | 76 | then min([fraction(amount, elapsedBlocks, lockLength), amount]) | |
77 | 77 | else 0 | |
78 | 78 | $Tuple2(unlockedAmount, (amount - unlockedAmount)) | |
79 | 79 | } | |
80 | 80 | ||
81 | 81 | ||
82 | 82 | func getUserUnlockedAmount (userAddress,id) = { | |
83 | 83 | let $t024372516 = parseUserVesting(userAddress, id) | |
84 | 84 | let vestingAmount = $t024372516._1 | |
85 | 85 | let startBlock = $t024372516._2 | |
86 | 86 | let lockLength = $t024372516._3 | |
87 | 87 | let $t025192616 = calcUnlockedAmount(vestingAmount, startBlock, lockLength) | |
88 | 88 | let unlockedAmount = $t025192616._1 | |
89 | 89 | let remainingAmount = $t025192616._2 | |
90 | 90 | $Tuple2(unlockedAmount, remainingAmount) | |
91 | 91 | } | |
92 | 92 | ||
93 | 93 | ||
94 | 94 | func getUserClaimActions (userAddress,id) = { | |
95 | 95 | let $t027192798 = parseUserVesting(userAddress, id) | |
96 | 96 | let vestingAmount = $t027192798._1 | |
97 | 97 | let startBlock = $t027192798._2 | |
98 | 98 | let lockLength = $t027192798._3 | |
99 | 99 | let $t028012879 = getUserUnlockedAmount(userAddress, id) | |
100 | 100 | let unlockedAmount = $t028012879._1 | |
101 | 101 | let remainingAmount = $t028012879._2 | |
102 | 102 | let remainingBlocks = max([((startBlock + lockLength) - height), 0]) | |
103 | 103 | if ((unlockedAmount != 0)) | |
104 | 104 | then [ScriptTransfer(addressFromStringValue(userAddress), unlockedAmount, assetIdBytes), StringEntry(keyUserVesting(userAddress, id), formatUserVesting(remainingAmount, height, remainingBlocks))] | |
105 | 105 | else nil | |
106 | 106 | } | |
107 | 107 | ||
108 | 108 | ||
109 | 109 | func getNewVestingActions (userAddress,id,vestingAmount,startBlock,lockLength) = [StringEntry(keyUserVesting(userAddress, id), formatUserVesting(vestingAmount, startBlock, lockLength))] | |
110 | 110 | ||
111 | 111 | ||
112 | 112 | func getAllUserClaimActions (userAddress) = { | |
113 | 113 | func actionsHelper (allActions,a) = (allActions ++ getUserClaimActions(userAddress, a)) | |
114 | 114 | ||
115 | 115 | let $l = IDS_LIST | |
116 | 116 | let $s = size($l) | |
117 | 117 | let $acc0 = nil | |
118 | 118 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
119 | 119 | then $a | |
120 | 120 | else actionsHelper($a, $l[$i]) | |
121 | 121 | ||
122 | 122 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
123 | 123 | then $a | |
124 | 124 | else throw("List size exceeds 30") | |
125 | 125 | ||
126 | 126 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30) | |
127 | 127 | } | |
128 | 128 | ||
129 | 129 | ||
130 | - | func getAvailableId (userAddress) = nil | |
130 | + | func getAvailableVestingId (userAddress) = { | |
131 | + | func helper (availableId,id) = { | |
132 | + | let $t037583837 = parseUserVesting(userAddress, id) | |
133 | + | let vestingAmount = $t037583837._1 | |
134 | + | let startBlock = $t037583837._2 | |
135 | + | let lockLength = $t037583837._3 | |
136 | + | if ((vestingAmount > 0)) | |
137 | + | then availableId | |
138 | + | else if ((availableId == -1)) | |
139 | + | then id | |
140 | + | else min([availableId, id]) | |
141 | + | } | |
142 | + | ||
143 | + | let availableId = { | |
144 | + | let $l = IDS_LIST | |
145 | + | let $s = size($l) | |
146 | + | let $acc0 = -1 | |
147 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
148 | + | then $a | |
149 | + | else helper($a, $l[$i]) | |
150 | + | ||
151 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
152 | + | then $a | |
153 | + | else throw("List size exceeds 30") | |
154 | + | ||
155 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30) | |
156 | + | } | |
157 | + | if ((availableId == -1)) | |
158 | + | then throwErr(makeString(["user exceeded max vesting count: ", userAddress], " ")) | |
159 | + | else availableId | |
160 | + | } | |
131 | 161 | ||
132 | 162 | ||
133 | 163 | @Callable(i) | |
134 | 164 | func foo (userAddress,vestingAmount,startBlock,lockLength) = getNewVestingActions(userAddress, 0, vestingAmount, startBlock, lockLength) | |
135 | 165 | ||
136 | 166 |
github/deemru/w8io/169f3d6 39.32 ms ◑