tx · GJgHWHssEwXM3uEng789AxfCXnvBHtpa3oYkfh164TtW 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.00800000 Waves 2022.11.30 20:35 [2340142] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "GJgHWHssEwXM3uEng789AxfCXnvBHtpa3oYkfh164TtW", "fee": 800000, "feeAssetId": null, "timestamp": 1669829740531, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "2MpUXTtGS2RgYQ6TBFi9WZcEZ5Tp3PztEEw32mk3J6kKM9Lqd4tJ8wNG7YMWCY5Cch2HCuN6mjh5RY1LeMn1NWTe" ], "script": "base64:BgIJCAISAwoBCBIAEgAGU2NhbGU2AMCEPQAGU2NhbGU4AIDC1y8AB1NjYWxlMTYJAGgCBQZTY2FsZTgFBlNjYWxlOAAKdmFsaWRhdG9ycwkAzAgCAiMzTkFtcUdqeFJCUlBvUkhaVVVxdmhpTlM2YXhuR3BpbkxIQwUDbmlsAAdhc3NldElkAixISG1hRlFwVW9id0t4emp6NEVDYUJQdG9GNjlrdWpLd1UyY296YVV6VHNndgALcHV6emxlUG9vbHMJAMwIAgIjM042U3RKZGdtVGZBUnNSTm45WHQ1ckRZRXMzcHI0S0d5MXYFA25pbAEKZ2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgRVbml0BAF4BQckbWF0Y2gwCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQkA8AcCBQR0aGlzCQEFdmFsdWUBBQdhc3NldElkAQl0cnlHZXRJbnQCB2FkZHJlc3MDa2V5BAckbWF0Y2gwCQCaCAIFB2FkZHJlc3MFA2tleQMJAAECBQckbWF0Y2gwAgNJbnQEAWIFByRtYX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CnZhbGlkYXRvcnMJAKUIAQgFAWkGY2FsbGVyBQR1bml0CQACAQINQWNjZXNzIGRlbmllZAMJAAACBQtjdXJyZW50UG9vbAUGcG9vbElkCQACAQkArAICAhNBbHJlYWR5IHN1cHBsaWVkIHRvBQtjdXJyZW50UG9vbAQKd2l0aGRyYXdUeAkBDndpdGhkcmF3UmVzdWx0AAMJAAACBQp3aXRoZHJhd1R4BQp3aXRoZHJhd1R4CQDOCAIJAQxzdXBwbHlSZXN1bHQBBQZwb29sSWQJAQxyZWNhbGNSZXN1bHQBAAAJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BaQEFc3Rha2UABAR1c2VyCQClCAEIBQFpBmNhbGxlcgQGYW1vdW50CAkAkQMCCAUBaQhwYXltZW50cwAABmFtb3VudAQLY3VycmVudFBvb2wJAQl0cnlHZXRTdHICBQR0aGlzAgtjdXJyZW50UG9vbAMDCQBnAgAABQZhbW91bnQGCQECIT0CCAkAkQMCCAUBaQhwYXltZW50cwAAB2Fzc2V0SWQJANkEAQUHYXNzZXRJZAkAAgECFmludmFsaWQgdG9rZW4gYXR0YWNoZWQDCQAAAgULY3VycmVudFBvb2wCAAkAAgECFFBvb2wgbm90IGluaXRpYWxpemVkCQDOCAIJAQtzdGFrZVJlc3VsdAIFBHVzZXIFBmFtb3VudAkBDHN1cHBseVJlc3VsdAEFC2N1cnJlbnRQb29sAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleSz35Ew=", "height": 2340142, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9nFkN9cAaP6JP4nE4HasH9i22D1swvkewz8zFJKLStZS Next: G3MuSEZ7UCSPQw5t9jCEnG9uKotau9x64PZjbQtw6Po Diff:
Old | New | Differences | |
---|---|---|---|
7 | 7 | ||
8 | 8 | let Scale16 = (Scale8 * Scale8) | |
9 | 9 | ||
10 | - | let validators = [""] | |
10 | + | let validators = ["3NAmqGjxRBRPoRHZUUqvhiNS6axnGpinLHC"] | |
11 | 11 | ||
12 | 12 | let assetId = "HHmaFQpUobwKxzjz4ECaBPtoF69kujKwU2cozaUzTsgv" | |
13 | 13 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let Scale6 = 1000000 | |
5 | 5 | ||
6 | 6 | let Scale8 = 100000000 | |
7 | 7 | ||
8 | 8 | let Scale16 = (Scale8 * Scale8) | |
9 | 9 | ||
10 | - | let validators = [""] | |
10 | + | let validators = ["3NAmqGjxRBRPoRHZUUqvhiNS6axnGpinLHC"] | |
11 | 11 | ||
12 | 12 | let assetId = "HHmaFQpUobwKxzjz4ECaBPtoF69kujKwU2cozaUzTsgv" | |
13 | 13 | ||
14 | 14 | let puzzlePools = ["3N6StJdgmTfARsRNn9Xt5rDYEs3pr4KGy1v"] | |
15 | 15 | ||
16 | 16 | func getBalance (assetId) = match assetId { | |
17 | 17 | case x: Unit => | |
18 | 18 | wavesBalance(this).available | |
19 | 19 | case _ => | |
20 | 20 | assetBalance(this, value(assetId)) | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func tryGetInt (address,key) = match getInteger(address, key) { | |
25 | 25 | case b: Int => | |
26 | 26 | b | |
27 | 27 | case _ => | |
28 | 28 | 0 | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func tryGetStr (address,key) = match getString(address, key) { | |
33 | 33 | case b: String => | |
34 | 34 | b | |
35 | 35 | case _ => | |
36 | 36 | "" | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getAssetString (assetId) = match assetId { | |
41 | 41 | case b: ByteVector => | |
42 | 42 | toBase58String(b) | |
43 | 43 | case _ => | |
44 | 44 | "WAVES" | |
45 | 45 | } | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func getPuzzlePoolSuppliedAmount (poolId) = { | |
49 | 49 | let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId)) | |
50 | 50 | balance | |
51 | 51 | } | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func getTotalSuppliedAmount () = { | |
55 | 55 | let currentPool = tryGetStr(this, "currentPool") | |
56 | 56 | if ((currentPool == "")) | |
57 | 57 | then throw(("Cannot find pool with id " + currentPool)) | |
58 | 58 | else getPuzzlePoolSuppliedAmount(currentPool) | |
59 | 59 | } | |
60 | 60 | ||
61 | 61 | ||
62 | 62 | func withdrawFromPuzzlePool (poolId,amount) = { | |
63 | 63 | let poolAddress = Address(fromBase58String(poolId)) | |
64 | 64 | let withdrawTx = if ((amount > 0)) | |
65 | 65 | then invoke(poolAddress, "withdraw", [assetId, amount], nil) | |
66 | 66 | else "" | |
67 | 67 | if ((withdrawTx == withdrawTx)) | |
68 | 68 | then withdrawTx | |
69 | 69 | else throw("Strict value is not equal to itself.") | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | func calculateSRate () = { | |
74 | 74 | let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate") | |
75 | 75 | let stakedAmount = tryGetInt(this, "global_staked") | |
76 | 76 | let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight") | |
77 | 77 | let blocks = (height - lastCheckHeight) | |
78 | 78 | let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8)) | |
79 | 79 | if ((stakedAmount == 0)) | |
80 | 80 | then Scale8 | |
81 | 81 | else { | |
82 | 82 | let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount)) | |
83 | 83 | if ((Scale8 > sRate)) | |
84 | 84 | then Scale8 | |
85 | 85 | else sRate | |
86 | 86 | } | |
87 | 87 | } | |
88 | 88 | ||
89 | 89 | ||
90 | 90 | func recalcResult (stakedChange) = { | |
91 | 91 | let stakedAmount = tryGetInt(this, "global_staked") | |
92 | 92 | let sRate = calculateSRate() | |
93 | 93 | [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)] | |
94 | 94 | } | |
95 | 95 | ||
96 | 96 | ||
97 | 97 | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
98 | 98 | then throw(("Unknown poolId " + poolId)) | |
99 | 99 | else { | |
100 | 100 | let assetBytes = fromBase58String(assetId) | |
101 | 101 | let balance = getBalance(assetBytes) | |
102 | 102 | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
103 | 103 | if ((inv == inv)) | |
104 | 104 | then [StringEntry("currentPool", poolId)] | |
105 | 105 | else throw("Strict value is not equal to itself.") | |
106 | 106 | } | |
107 | 107 | ||
108 | 108 | ||
109 | 109 | func withdrawResult () = { | |
110 | 110 | let currentPool = tryGetStr(this, "currentPool") | |
111 | 111 | if ((currentPool == "")) | |
112 | 112 | then throw(("Cannot find pool with id " + currentPool)) | |
113 | 113 | else { | |
114 | 114 | let amount = getPuzzlePoolSuppliedAmount(currentPool) | |
115 | 115 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
116 | 116 | if ((tx == tx)) | |
117 | 117 | then tx | |
118 | 118 | else throw("Strict value is not equal to itself.") | |
119 | 119 | } | |
120 | 120 | } | |
121 | 121 | ||
122 | 122 | ||
123 | 123 | func stakeResult (user,amount) = { | |
124 | 124 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
125 | 125 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
126 | 126 | } | |
127 | 127 | ||
128 | 128 | ||
129 | 129 | @Callable(i) | |
130 | 130 | func rebalance (poolId) = { | |
131 | 131 | let currentPool = tryGetStr(this, "currentPool") | |
132 | 132 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
133 | 133 | then throw("Access denied") | |
134 | 134 | else if ((currentPool == poolId)) | |
135 | 135 | then throw(("Already supplied to" + currentPool)) | |
136 | 136 | else { | |
137 | 137 | let withdrawTx = withdrawResult() | |
138 | 138 | if ((withdrawTx == withdrawTx)) | |
139 | 139 | then (supplyResult(poolId) ++ recalcResult(0)) | |
140 | 140 | else throw("Strict value is not equal to itself.") | |
141 | 141 | } | |
142 | 142 | } | |
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | 146 | @Callable(i) | |
147 | 147 | func stake () = { | |
148 | 148 | let user = toString(i.caller) | |
149 | 149 | let amount = i.payments[0].amount | |
150 | 150 | let currentPool = tryGetStr(this, "currentPool") | |
151 | 151 | if (if ((0 >= amount)) | |
152 | 152 | then true | |
153 | 153 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
154 | 154 | then throw("invalid token attached") | |
155 | 155 | else if ((currentPool == "")) | |
156 | 156 | then throw("Pool not initialized") | |
157 | 157 | else (stakeResult(user, amount) ++ supplyResult(currentPool)) | |
158 | 158 | } | |
159 | 159 | ||
160 | 160 | ||
161 | 161 | @Verifier(tx) | |
162 | 162 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
163 | 163 |
github/deemru/w8io/169f3d6 26.48 ms ◑