tx · 7eXrXzaVWkdgVs98T6rPjZVJ7r1Y6tj5q6L19mKBurQm 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.00900000 Waves 2022.12.07 01:44 [2349101] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "7eXrXzaVWkdgVs98T6rPjZVJ7r1Y6tj5q6L19mKBurQm", "fee": 900000, "feeAssetId": null, "timestamp": 1670366667757, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "5qtnKWpiRWb4XW1FE1SZckNQQt9WdjeWBpWp2YxsUG78BYGBPT9TnsUvPWzE9hF1joCiYDGQHtcrCEgDwZxKKSFB" ], "script": "base64:BgITCAISAwoBCBIDCgEIEgASAwoBARYABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAPbW9uZXlCb3hBZGRyZXNzCQEHQWRkcmVzcwEBGgFUZKnP467xWXotJQOt2k8QiNBvrQpHH8SpAAdhc3NldElkAixISG1hRlFwVW9id0t4emp6NEVDYUJQdG9GNjlrdWpLd1UyY296YVV6VHNndgALcHV6emxlUG9vbHMJAMwIAgIjM042U3RKZGdtVGZBUnNSTm45WHQ1ckRZRXMzcHI0S0d5MXYFA25pbAEKZ2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgRVbml0BAF4BQckbWF0Y2gwCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQkA8AcCBQR0aGlzCQEFdmFsdWUBBQdhc3NldElkAQl0cnlHZXRJbnQCB2FkZH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50CAkAkQMCCAUBaQhwYXltZW50cwAABmFtb3VudAQLY3VycmVudFBvb2wJAQl0cnlHZXRTdHICBQR0aGlzAgtjdXJyZW50UG9vbAMDCQBnAgAABQZhbW91bnQGCQECIT0CCAkAkQMCCAUBaQhwYXltZW50cwAAB2Fzc2V0SWQJANkEAQUHYXNzZXRJZAkAAgECFmludmFsaWQgdG9rZW4gYXR0YWNoZWQDCQAAAgULY3VycmVudFBvb2wCAAkAAgECFFBvb2wgbm90IGluaXRpYWxpemVkBANmZWUJAQxjYWxjdWxhdGVGZWUACQDOCAIJAQtzdGFrZVJlc3VsdAIFBHVzZXIFBmFtb3VudAkBDHN1cHBseVJlc3VsdAIFC2N1cnJlbnRQb29sBQNmZWUBaQEHdW5zdGFrZQEGYW1vdW50BAR1c2VyCQClCAEIBQFpBmNhbGxlcgQLY3VycmVudFBvb2wJAQl0cnlHZXRTdHICBQR0aGlzAgtjdXJyZW50UG9vbAQDZmVlCQEMY2FsY3VsYXRlRmVlAAQFYXNzZXQJANkEAQUHYXNzZXRJZAkAzggCCQENdW5zdGFrZVJlc3VsdAIFBHVzZXIFBmFtb3VudAkBCWRvVW5zdGFrZQQFC2N1cnJlbnRQb29sCAUBaQZjYWxsZXIFBmFtb3VudAUDZmVlAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleQbrdcM=", "height": 2349101, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6yHNs9NXxA2wdRXzugyjU2Js7TbqU8uVb2xr2ZqaSXSY Next: 6X9nJY2a5MHNTh6Dv3asvksAVwHaUYgUJvknNfJWsYUB Diff:
Old | New | Differences | |
---|---|---|---|
109 | 109 | } | |
110 | 110 | ||
111 | 111 | ||
112 | - | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
112 | + | func supplyResult (poolId,fee) = 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 | - | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
118 | - | if ((inv == inv)) | |
119 | - | then [StringEntry("currentPool", poolId)] | |
117 | + | let supplyTx = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
118 | + | if ((supplyTx == supplyTx)) | |
119 | + | then { | |
120 | + | let withdrawFeeTx = withdrawFromPuzzlePool(poolId, fee) | |
121 | + | if ((withdrawFeeTx == withdrawFeeTx)) | |
122 | + | then [StringEntry("currentPool", poolId), ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
123 | + | else throw("Strict value is not equal to itself.") | |
124 | + | } | |
120 | 125 | else throw("Strict value is not equal to itself.") | |
121 | 126 | } | |
122 | - | ||
123 | - | ||
124 | - | func chargeFeeResult (poolId,fee) = { | |
125 | - | let withdrawFeeTx = withdrawFromPuzzlePool(poolId, fee) | |
126 | - | if ((withdrawFeeTx == withdrawFeeTx)) | |
127 | - | then [ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
128 | - | else throw("Strict value is not equal to itself.") | |
129 | - | } | |
130 | 127 | ||
131 | 128 | ||
132 | 129 | func withdrawResult () = { | |
159 | 156 | } | |
160 | 157 | ||
161 | 158 | ||
162 | - | func | |
163 | - | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
159 | + | func doUnstake (currentPool,caller,amount,fee) = { | |
160 | + | let tx = withdrawFromPuzzlePool(currentPool, (amount + fee)) | |
164 | 161 | if ((tx == tx)) | |
165 | - | then [ScriptTransfer(caller, amount, fromBase58String(assetId))] | |
162 | + | then [ScriptTransfer(caller, amount, fromBase58String(assetId)), ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
166 | 163 | else throw("Strict value is not equal to itself.") | |
167 | 164 | } | |
168 | 165 | ||
189 | 186 | else { | |
190 | 187 | let withdrawTx = withdrawResult() | |
191 | 188 | if ((withdrawTx == withdrawTx)) | |
192 | - | then supplyResult(poolId) | |
189 | + | then (supplyResult(poolId, 0) ++ recalcResult(0)) | |
193 | 190 | else throw("Strict value is not equal to itself.") | |
194 | 191 | } | |
195 | 192 | } | |
209 | 206 | then throw("Pool not initialized") | |
210 | 207 | else { | |
211 | 208 | let fee = calculateFee() | |
212 | - | ( | |
209 | + | (stakeResult(user, amount) ++ supplyResult(currentPool, fee)) | |
213 | 210 | } | |
214 | 211 | } | |
215 | 212 | ||
221 | 218 | let currentPool = tryGetStr(this, "currentPool") | |
222 | 219 | let fee = calculateFee() | |
223 | 220 | let asset = fromBase58String(assetId) | |
224 | - | | |
221 | + | (unstakeResult(user, amount) ++ doUnstake(currentPool, i.caller, amount, fee)) | |
225 | 222 | } | |
226 | 223 | ||
227 | 224 |
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 | - | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
112 | + | func supplyResult (poolId,fee) = 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 | - | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
118 | - | if ((inv == inv)) | |
119 | - | then [StringEntry("currentPool", poolId)] | |
117 | + | let supplyTx = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
118 | + | if ((supplyTx == supplyTx)) | |
119 | + | then { | |
120 | + | let withdrawFeeTx = withdrawFromPuzzlePool(poolId, fee) | |
121 | + | if ((withdrawFeeTx == withdrawFeeTx)) | |
122 | + | then [StringEntry("currentPool", poolId), ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
123 | + | else throw("Strict value is not equal to itself.") | |
124 | + | } | |
120 | 125 | else throw("Strict value is not equal to itself.") | |
121 | 126 | } | |
122 | - | ||
123 | - | ||
124 | - | func chargeFeeResult (poolId,fee) = { | |
125 | - | let withdrawFeeTx = withdrawFromPuzzlePool(poolId, fee) | |
126 | - | if ((withdrawFeeTx == withdrawFeeTx)) | |
127 | - | then [ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
128 | - | else throw("Strict value is not equal to itself.") | |
129 | - | } | |
130 | 127 | ||
131 | 128 | ||
132 | 129 | func withdrawResult () = { | |
133 | 130 | let currentPool = tryGetStr(this, "currentPool") | |
134 | 131 | if ((currentPool == "")) | |
135 | 132 | then throw(("Cannot find pool with id " + currentPool)) | |
136 | 133 | else { | |
137 | 134 | let amount = getPuzzlePoolSuppliedAmount(currentPool) | |
138 | 135 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
139 | 136 | if ((tx == tx)) | |
140 | 137 | then tx | |
141 | 138 | else throw("Strict value is not equal to itself.") | |
142 | 139 | } | |
143 | 140 | } | |
144 | 141 | ||
145 | 142 | ||
146 | 143 | func stakeResult (user,amount) = { | |
147 | 144 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
148 | 145 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
149 | 146 | } | |
150 | 147 | ||
151 | 148 | ||
152 | 149 | func unstakeResult (user,amount) = { | |
153 | 150 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
154 | 151 | let userStaked = tryGetInt(this, (user + "_staked")) | |
155 | 152 | let unstakeAmount = if ((sAmount > userStaked)) | |
156 | 153 | then userStaked | |
157 | 154 | else sAmount | |
158 | 155 | (recalcResult(-(unstakeAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))]) | |
159 | 156 | } | |
160 | 157 | ||
161 | 158 | ||
162 | - | func | |
163 | - | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
159 | + | func doUnstake (currentPool,caller,amount,fee) = { | |
160 | + | let tx = withdrawFromPuzzlePool(currentPool, (amount + fee)) | |
164 | 161 | if ((tx == tx)) | |
165 | - | then [ScriptTransfer(caller, amount, fromBase58String(assetId))] | |
162 | + | then [ScriptTransfer(caller, amount, fromBase58String(assetId)), ScriptTransfer(moneyBoxAddress, fee, fromBase58String(assetId))] | |
166 | 163 | else throw("Strict value is not equal to itself.") | |
167 | 164 | } | |
168 | 165 | ||
169 | 166 | ||
170 | 167 | @Callable(i) | |
171 | 168 | func init (poolId) = { | |
172 | 169 | let currentPool = tryGetStr(this, "currentPool") | |
173 | 170 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
174 | 171 | then throw("Access denied") | |
175 | 172 | else if ((currentPool == "")) | |
176 | 173 | then [StringEntry("currentPool", poolId)] | |
177 | 174 | else nil | |
178 | 175 | } | |
179 | 176 | ||
180 | 177 | ||
181 | 178 | ||
182 | 179 | @Callable(i) | |
183 | 180 | func rebalance (poolId) = { | |
184 | 181 | let currentPool = tryGetStr(this, "currentPool") | |
185 | 182 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
186 | 183 | then throw("Access denied") | |
187 | 184 | else if ((currentPool == poolId)) | |
188 | 185 | then throw(("Already supplied to" + currentPool)) | |
189 | 186 | else { | |
190 | 187 | let withdrawTx = withdrawResult() | |
191 | 188 | if ((withdrawTx == withdrawTx)) | |
192 | - | then supplyResult(poolId) | |
189 | + | then (supplyResult(poolId, 0) ++ recalcResult(0)) | |
193 | 190 | else throw("Strict value is not equal to itself.") | |
194 | 191 | } | |
195 | 192 | } | |
196 | 193 | ||
197 | 194 | ||
198 | 195 | ||
199 | 196 | @Callable(i) | |
200 | 197 | func stake () = { | |
201 | 198 | let user = toString(i.caller) | |
202 | 199 | let amount = i.payments[0].amount | |
203 | 200 | let currentPool = tryGetStr(this, "currentPool") | |
204 | 201 | if (if ((0 >= amount)) | |
205 | 202 | then true | |
206 | 203 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
207 | 204 | then throw("invalid token attached") | |
208 | 205 | else if ((currentPool == "")) | |
209 | 206 | then throw("Pool not initialized") | |
210 | 207 | else { | |
211 | 208 | let fee = calculateFee() | |
212 | - | ( | |
209 | + | (stakeResult(user, amount) ++ supplyResult(currentPool, fee)) | |
213 | 210 | } | |
214 | 211 | } | |
215 | 212 | ||
216 | 213 | ||
217 | 214 | ||
218 | 215 | @Callable(i) | |
219 | 216 | func unstake (amount) = { | |
220 | 217 | let user = toString(i.caller) | |
221 | 218 | let currentPool = tryGetStr(this, "currentPool") | |
222 | 219 | let fee = calculateFee() | |
223 | 220 | let asset = fromBase58String(assetId) | |
224 | - | | |
221 | + | (unstakeResult(user, amount) ++ doUnstake(currentPool, i.caller, amount, fee)) | |
225 | 222 | } | |
226 | 223 | ||
227 | 224 | ||
228 | 225 | @Verifier(tx) | |
229 | 226 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
230 | 227 |
github/deemru/w8io/026f985 44.17 ms ◑