tx · 9owH2PA3p7PBCapTvqHBTfMXtKhNNgqCNMCNWu4azLnS 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.00900000 Waves 2022.12.01 18:45 [2341477] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "9owH2PA3p7PBCapTvqHBTfMXtKhNNgqCNMCNWu4azLnS", "fee": 900000, "feeAssetId": null, "timestamp": 1669909628914, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "5M6FzMWY5qTiSnov731vErZQPzRvwhzgE135MHG3qeavAt31e1meDKiTUMoMKLpPbha5rL2Kc4sHMXF3BUZMNTAG" ], "script": "base64:BgITCAISAwoBCBIDCgEIEgASAwoBARMABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAHYXNzZXRJZAIsSEhtYUZRcFVvYndLeHpqejRFQ2FCUHRvRjY5a3VqS3dVMmNvemFVelRzZ3YAC3B1enpsZVBvb2xzCQDMCAICIzNONlN0SmRnbVRmQVJzUk5uOVh0NXJEWUVzM3ByNEtHeTF2BQNuaWwBCmdldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIEVW5pdAQBeAUHJG1hdGNoMAgJAO8HAQUEdGhpcwlhdmFpbGFibGUJAPAHAgUEdGhpcwkBBXZhbHVlAQUHYXNzZXRJZAEJdHJ5R2V0SW50AgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoMAIDSW50BAF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QEdXNlcgkApQgBCAUBaQZjYWxsZXIEBmFtb3VudAgJAJEDAggFAWkIcGF5bWVudHMAAAZhbW91bnQEC2N1cnJlbnRQb29sCQEJdHJ5R2V0U3RyAgUEdGhpcwILY3VycmVudFBvb2wDAwkAZwIAAAUGYW1vdW50BgkBAiE9AggJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkCQDZBAEFB2Fzc2V0SWQJAAIBAhZpbnZhbGlkIHRva2VuIGF0dGFjaGVkAwkAAAIFC2N1cnJlbnRQb29sAgAJAAIBAhRQb29sIG5vdCBpbml0aWFsaXplZAkAzggCCQELc3Rha2VSZXN1bHQCBQR1c2VyBQZhbW91bnQJAQxzdXBwbHlSZXN1bHQBBQtjdXJyZW50UG9vbAFpAQd1bnN0YWtlAQZhbW91bnQEBHVzZXIJAKUIAQgFAWkGY2FsbGVyBAtjdXJyZW50UG9vbAkBCXRyeUdldFN0cgIFBHRoaXMCC2N1cnJlbnRQb29sBAJ0eAkBFndpdGhkcmF3RnJvbVB1enpsZVBvb2wCBQtjdXJyZW50UG9vbAUGYW1vdW50AwkAAAIFAnR4BQJ0eAkAzggCCQENdW5zdGFrZVJlc3VsdAIFBHVzZXIFBmFtb3VudAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIFBmFtb3VudAkA2QQBBQdhc3NldElkBQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5U6Ufrw==", "height": 2341477, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9R6erxBzUKkVB27ngEBAaafaT1pWM9JJMBou7jjts4fs Next: GQUPP2Pu1H1yxzXsa123npXeYvUbjTjNhzSFUA2wkq2U Diff:
Old | New | Differences | |
---|---|---|---|
126 | 126 | } | |
127 | 127 | ||
128 | 128 | ||
129 | + | func unstakeResult (user,amount) = { | |
130 | + | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
131 | + | let userStaked = tryGetInt(this, (user + "_staked")) | |
132 | + | let unstakeAmount = if ((sAmount > userStaked)) | |
133 | + | then userStaked | |
134 | + | else sAmount | |
135 | + | (recalcResult(-(sAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))]) | |
136 | + | } | |
137 | + | ||
138 | + | ||
129 | 139 | @Callable(i) | |
130 | 140 | func init (poolId) = { | |
131 | 141 | let currentPool = tryGetStr(this, "currentPool") | |
170 | 180 | } | |
171 | 181 | ||
172 | 182 | ||
183 | + | ||
184 | + | @Callable(i) | |
185 | + | func unstake (amount) = { | |
186 | + | let user = toString(i.caller) | |
187 | + | let currentPool = tryGetStr(this, "currentPool") | |
188 | + | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
189 | + | if ((tx == tx)) | |
190 | + | then (unstakeResult(user, amount) ++ [ScriptTransfer(i.caller, amount, fromBase58String(assetId))]) | |
191 | + | else throw("Strict value is not equal to itself.") | |
192 | + | } | |
193 | + | ||
194 | + | ||
173 | 195 | @Verifier(tx) | |
174 | 196 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
175 | 197 |
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 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 | + | func unstakeResult (user,amount) = { | |
130 | + | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
131 | + | let userStaked = tryGetInt(this, (user + "_staked")) | |
132 | + | let unstakeAmount = if ((sAmount > userStaked)) | |
133 | + | then userStaked | |
134 | + | else sAmount | |
135 | + | (recalcResult(-(sAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))]) | |
136 | + | } | |
137 | + | ||
138 | + | ||
129 | 139 | @Callable(i) | |
130 | 140 | func init (poolId) = { | |
131 | 141 | let currentPool = tryGetStr(this, "currentPool") | |
132 | 142 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
133 | 143 | then throw("Access denied") | |
134 | 144 | else if ((currentPool == "")) | |
135 | 145 | then [StringEntry("currentPool", poolId)] | |
136 | 146 | else nil | |
137 | 147 | } | |
138 | 148 | ||
139 | 149 | ||
140 | 150 | ||
141 | 151 | @Callable(i) | |
142 | 152 | func rebalance (poolId) = { | |
143 | 153 | let currentPool = tryGetStr(this, "currentPool") | |
144 | 154 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
145 | 155 | then throw("Access denied") | |
146 | 156 | else if ((currentPool == poolId)) | |
147 | 157 | then throw(("Already supplied to" + currentPool)) | |
148 | 158 | else { | |
149 | 159 | let withdrawTx = withdrawResult() | |
150 | 160 | if ((withdrawTx == withdrawTx)) | |
151 | 161 | then (supplyResult(poolId) ++ recalcResult(0)) | |
152 | 162 | else throw("Strict value is not equal to itself.") | |
153 | 163 | } | |
154 | 164 | } | |
155 | 165 | ||
156 | 166 | ||
157 | 167 | ||
158 | 168 | @Callable(i) | |
159 | 169 | func stake () = { | |
160 | 170 | let user = toString(i.caller) | |
161 | 171 | let amount = i.payments[0].amount | |
162 | 172 | let currentPool = tryGetStr(this, "currentPool") | |
163 | 173 | if (if ((0 >= amount)) | |
164 | 174 | then true | |
165 | 175 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
166 | 176 | then throw("invalid token attached") | |
167 | 177 | else if ((currentPool == "")) | |
168 | 178 | then throw("Pool not initialized") | |
169 | 179 | else (stakeResult(user, amount) ++ supplyResult(currentPool)) | |
170 | 180 | } | |
171 | 181 | ||
172 | 182 | ||
183 | + | ||
184 | + | @Callable(i) | |
185 | + | func unstake (amount) = { | |
186 | + | let user = toString(i.caller) | |
187 | + | let currentPool = tryGetStr(this, "currentPool") | |
188 | + | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
189 | + | if ((tx == tx)) | |
190 | + | then (unstakeResult(user, amount) ++ [ScriptTransfer(i.caller, amount, fromBase58String(assetId))]) | |
191 | + | else throw("Strict value is not equal to itself.") | |
192 | + | } | |
193 | + | ||
194 | + | ||
173 | 195 | @Verifier(tx) | |
174 | 196 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
175 | 197 |
github/deemru/w8io/169f3d6 36.12 ms ◑