tx · G27ZPgtsToTpCweFXxVRqoJHodazBMLqGLut2KGefwFv 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.01000000 Waves 2022.12.07 02:12 [2349127] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "G27ZPgtsToTpCweFXxVRqoJHodazBMLqGLut2KGefwFv", "fee": 1000000, "feeAssetId": null, "timestamp": 1670368330456, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "FkgNEHxcxdhVqB34NtTURd917vubD58fArnsAxzDZoo6vUSEUugNjDxwDeLnjKWzeqBxUoFeT1DQaWQka23yPjr" ], "script": "base64:BgITCAISAwoBCBIDCgEIEgASAwoBARcABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAPbW9uZXlCb3hBZGRyZXNzCQEHQWRkcmVzcwEBGgFUZKnP467xWXotJQOt2k8QiNBvrQpHH8SpAAdhc3NldElkAixISG1hRlFwVW9id0t4emp6NEVDYUJQdG9GNjlrdWpLd1UyY296YVV6VHNndgALcHV6emxlUG9vbHMJAMwIAgIjM042U3RKZGdtVGZBUnNSTm45WHQ1ckRZRXMzcHI0S0d5MXYFA25pbAEKZ2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgRVbml0BAF4BQckbWF0Y2gwCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQkA8AcCBQR0aGlzCQEFdmFsdWUBBQdhc3NldElkAQl0cnlHZXRJbnQCB2FkZHJlc3MDa2V5BAckbWF0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gJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleQ+Z8Us=", "height": 2349127, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9t5Ra2q65NC5sZiyBRz7i1P4xydTwYnGhQ5PcA8ZcFta Next: DFXagidqvtSvNB9NXPAufUXbiARjqbYWAzG5P5EGVEr5 Diff:
Old | New | Differences | |
---|---|---|---|
231 | 231 | func unstake (amount) = { | |
232 | 232 | let user = toString(i.caller) | |
233 | 233 | let currentPool = tryGetStr(this, "currentPool") | |
234 | + | let asset = fromBase58String(assetId) | |
234 | 235 | let fee = calculateFee() | |
235 | - | let asset = fromBase58String(assetId) | |
236 | - | ((unstakeResult(user, amount) ++ unstakeAndTransferResult(currentPool, i.caller, amount)) ++ chargeFeeResult(currentPool, fee)) | |
236 | + | let a = if ((fee > Scale6)) | |
237 | + | then "" | |
238 | + | else "" | |
239 | + | if ((a == a)) | |
240 | + | then ((unstakeResult(user, amount) ++ unstakeAndTransferResult(currentPool, i.caller, amount)) ++ chargeFeeResult(currentPool, fee)) | |
241 | + | else throw("Strict value is not equal to itself.") | |
237 | 242 | } | |
238 | 243 | ||
239 | 244 |
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 | 10 | let validators = ["3NAmqGjxRBRPoRHZUUqvhiNS6axnGpinLHC"] | |
11 | 11 | ||
12 | 12 | let moneyBoxAddress = Address(base58'3My6LmrRSRvJ73T14oT5k53SGPavGFoacWc') | |
13 | 13 | ||
14 | 14 | let assetId = "HHmaFQpUobwKxzjz4ECaBPtoF69kujKwU2cozaUzTsgv" | |
15 | 15 | ||
16 | 16 | let puzzlePools = ["3N6StJdgmTfARsRNn9Xt5rDYEs3pr4KGy1v"] | |
17 | 17 | ||
18 | 18 | func getBalance (assetId) = match assetId { | |
19 | 19 | case x: Unit => | |
20 | 20 | wavesBalance(this).available | |
21 | 21 | case _ => | |
22 | 22 | assetBalance(this, value(assetId)) | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func tryGetInt (address,key) = match getInteger(address, key) { | |
27 | 27 | case b: Int => | |
28 | 28 | b | |
29 | 29 | case _ => | |
30 | 30 | 0 | |
31 | 31 | } | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func tryGetStr (address,key) = match getString(address, key) { | |
35 | 35 | case b: String => | |
36 | 36 | b | |
37 | 37 | case _ => | |
38 | 38 | "" | |
39 | 39 | } | |
40 | 40 | ||
41 | 41 | ||
42 | 42 | func getAssetString (assetId) = match assetId { | |
43 | 43 | case b: ByteVector => | |
44 | 44 | toBase58String(b) | |
45 | 45 | case _ => | |
46 | 46 | "WAVES" | |
47 | 47 | } | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | func getPuzzlePoolSuppliedAmount (poolId) = { | |
51 | 51 | let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId)) | |
52 | 52 | balance | |
53 | 53 | } | |
54 | 54 | ||
55 | 55 | ||
56 | 56 | func getTotalSuppliedAmount () = { | |
57 | 57 | let currentPool = tryGetStr(this, "currentPool") | |
58 | 58 | if ((currentPool == "")) | |
59 | 59 | then throw(("Cannot find pool with id " + currentPool)) | |
60 | 60 | else getPuzzlePoolSuppliedAmount(currentPool) | |
61 | 61 | } | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | func withdrawFromPuzzlePool (poolId,amount) = { | |
65 | 65 | let poolAddress = Address(fromBase58String(poolId)) | |
66 | 66 | let withdrawTx = if ((amount > 0)) | |
67 | 67 | then invoke(poolAddress, "withdraw", [assetId, amount], nil) | |
68 | 68 | else "" | |
69 | 69 | if ((withdrawTx == withdrawTx)) | |
70 | 70 | then withdrawTx | |
71 | 71 | else throw("Strict value is not equal to itself.") | |
72 | 72 | } | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | func calculateFee () = { | |
76 | 76 | let stakedAmount = tryGetInt(this, "global_staked") | |
77 | 77 | let lastSRate = tryGetInt(this, "global_lastCheckSRate") | |
78 | 78 | let sAmount = fraction(stakedAmount, lastSRate, Scale8) | |
79 | 79 | let totalSupplied = getTotalSuppliedAmount() | |
80 | 80 | let diff = (totalSupplied - sAmount) | |
81 | 81 | let fee = fraction(diff, 5000000, Scale8) | |
82 | 82 | if ((fee > 0)) | |
83 | 83 | then fee | |
84 | 84 | else 0 | |
85 | 85 | } | |
86 | 86 | ||
87 | 87 | ||
88 | 88 | func calculateSRate () = { | |
89 | 89 | let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate") | |
90 | 90 | let stakedAmount = tryGetInt(this, "global_staked") | |
91 | 91 | let lastCheckSAmounut = fraction(stakedAmount, lastCheckSRate, Scale8) | |
92 | 92 | if ((lastCheckSRate == 0)) | |
93 | 93 | then Scale8 | |
94 | 94 | else if ((lastCheckSAmounut == 0)) | |
95 | 95 | then lastCheckSRate | |
96 | 96 | else { | |
97 | 97 | let sRate = fraction(lastCheckSRate, (fraction((fraction(getTotalSuppliedAmount(), Scale6, lastCheckSAmounut) - Scale6), (Scale8 - 5000000), Scale8) + Scale6), Scale6) | |
98 | 98 | if ((Scale8 > sRate)) | |
99 | 99 | then lastCheckSRate | |
100 | 100 | else sRate | |
101 | 101 | } | |
102 | 102 | } | |
103 | 103 | ||
104 | 104 | ||
105 | 105 | func recalcResult (stakedChange) = { | |
106 | 106 | let stakedAmount = tryGetInt(this, "global_staked") | |
107 | 107 | let sRate = calculateSRate() | |
108 | 108 | [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate)] | |
109 | 109 | } | |
110 | 110 | ||
111 | 111 | ||
112 | 112 | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
113 | 113 | then throw(("Unknown poolId " + poolId)) | |
114 | 114 | else { | |
115 | 115 | let assetBytes = fromBase58String(assetId) | |
116 | 116 | let balance = getBalance(assetBytes) | |
117 | 117 | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
118 | 118 | if ((inv == inv)) | |
119 | 119 | then [StringEntry("currentPool", poolId)] | |
120 | 120 | else throw("Strict value is not equal to itself.") | |
121 | 121 | } | |
122 | 122 | ||
123 | 123 | ||
124 | 124 | func chargeFeeResult (poolId,fee) = { | |
125 | 125 | let a = if ((fee > Scale6)) | |
126 | 126 | then throw(("1) Fee " + toString(fee))) | |
127 | 127 | else "" | |
128 | 128 | if ((a == a)) | |
129 | 129 | then { | |
130 | 130 | let withdrawFeeTx = withdrawFromPuzzlePool(poolId, fee) | |
131 | 131 | if ((withdrawFeeTx == withdrawFeeTx)) | |
132 | 132 | then [ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
133 | 133 | else throw("Strict value is not equal to itself.") | |
134 | 134 | } | |
135 | 135 | else throw("Strict value is not equal to itself.") | |
136 | 136 | } | |
137 | 137 | ||
138 | 138 | ||
139 | 139 | func withdrawResult () = { | |
140 | 140 | let currentPool = tryGetStr(this, "currentPool") | |
141 | 141 | if ((currentPool == "")) | |
142 | 142 | then throw(("Cannot find pool with id " + currentPool)) | |
143 | 143 | else { | |
144 | 144 | let amount = getPuzzlePoolSuppliedAmount(currentPool) | |
145 | 145 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
146 | 146 | if ((tx == tx)) | |
147 | 147 | then tx | |
148 | 148 | else throw("Strict value is not equal to itself.") | |
149 | 149 | } | |
150 | 150 | } | |
151 | 151 | ||
152 | 152 | ||
153 | 153 | func stakeResult (user,amount) = { | |
154 | 154 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
155 | 155 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
156 | 156 | } | |
157 | 157 | ||
158 | 158 | ||
159 | 159 | func unstakeResult (user,amount) = { | |
160 | 160 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
161 | 161 | let userStaked = tryGetInt(this, (user + "_staked")) | |
162 | 162 | let unstakeAmount = if ((sAmount > userStaked)) | |
163 | 163 | then userStaked | |
164 | 164 | else sAmount | |
165 | 165 | (recalcResult(-(unstakeAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))]) | |
166 | 166 | } | |
167 | 167 | ||
168 | 168 | ||
169 | 169 | func unstakeAndTransferResult (currentPool,caller,amount) = { | |
170 | 170 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
171 | 171 | if ((tx == tx)) | |
172 | 172 | then [ScriptTransfer(caller, amount, fromBase58String(assetId))] | |
173 | 173 | else throw("Strict value is not equal to itself.") | |
174 | 174 | } | |
175 | 175 | ||
176 | 176 | ||
177 | 177 | @Callable(i) | |
178 | 178 | func init (poolId) = { | |
179 | 179 | let currentPool = tryGetStr(this, "currentPool") | |
180 | 180 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
181 | 181 | then throw("Access denied") | |
182 | 182 | else if ((currentPool == "")) | |
183 | 183 | then [StringEntry("currentPool", poolId)] | |
184 | 184 | else nil | |
185 | 185 | } | |
186 | 186 | ||
187 | 187 | ||
188 | 188 | ||
189 | 189 | @Callable(i) | |
190 | 190 | func rebalance (poolId) = { | |
191 | 191 | let currentPool = tryGetStr(this, "currentPool") | |
192 | 192 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
193 | 193 | then throw("Access denied") | |
194 | 194 | else if ((currentPool == poolId)) | |
195 | 195 | then throw(("Already supplied to" + currentPool)) | |
196 | 196 | else { | |
197 | 197 | let withdrawTx = withdrawResult() | |
198 | 198 | if ((withdrawTx == withdrawTx)) | |
199 | 199 | then supplyResult(poolId) | |
200 | 200 | else throw("Strict value is not equal to itself.") | |
201 | 201 | } | |
202 | 202 | } | |
203 | 203 | ||
204 | 204 | ||
205 | 205 | ||
206 | 206 | @Callable(i) | |
207 | 207 | func stake () = { | |
208 | 208 | let user = toString(i.caller) | |
209 | 209 | let amount = i.payments[0].amount | |
210 | 210 | let currentPool = tryGetStr(this, "currentPool") | |
211 | 211 | if (if ((0 >= amount)) | |
212 | 212 | then true | |
213 | 213 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
214 | 214 | then throw("invalid token attached") | |
215 | 215 | else if ((currentPool == "")) | |
216 | 216 | then throw("Pool not initialized") | |
217 | 217 | else { | |
218 | 218 | let fee = calculateFee() | |
219 | 219 | let a = if ((fee > Scale6)) | |
220 | 220 | then "" | |
221 | 221 | else "" | |
222 | 222 | if ((a == a)) | |
223 | 223 | then ((stakeResult(user, amount) ++ supplyResult(currentPool)) ++ chargeFeeResult(currentPool, fee)) | |
224 | 224 | else throw("Strict value is not equal to itself.") | |
225 | 225 | } | |
226 | 226 | } | |
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | 230 | @Callable(i) | |
231 | 231 | func unstake (amount) = { | |
232 | 232 | let user = toString(i.caller) | |
233 | 233 | let currentPool = tryGetStr(this, "currentPool") | |
234 | + | let asset = fromBase58String(assetId) | |
234 | 235 | let fee = calculateFee() | |
235 | - | let asset = fromBase58String(assetId) | |
236 | - | ((unstakeResult(user, amount) ++ unstakeAndTransferResult(currentPool, i.caller, amount)) ++ chargeFeeResult(currentPool, fee)) | |
236 | + | let a = if ((fee > Scale6)) | |
237 | + | then "" | |
238 | + | else "" | |
239 | + | if ((a == a)) | |
240 | + | then ((unstakeResult(user, amount) ++ unstakeAndTransferResult(currentPool, i.caller, amount)) ++ chargeFeeResult(currentPool, fee)) | |
241 | + | else throw("Strict value is not equal to itself.") | |
237 | 242 | } | |
238 | 243 | ||
239 | 244 | ||
240 | 245 | @Verifier(tx) | |
241 | 246 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
242 | 247 |
github/deemru/w8io/026f985 60.41 ms ◑