tx · 9hoKb2GNrBgeAptCsQcjHqGunmQBMU7f7rDEvHLpXkjy 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.00900000 Waves 2022.12.01 20:16 [2341564] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "9hoKb2GNrBgeAptCsQcjHqGunmQBMU7f7rDEvHLpXkjy", "fee": 900000, "feeAssetId": null, "timestamp": 1669915111283, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "3GsVZgu2qeXRdz1qrUoSoF96xLZAupuxrrHemRaNZE9X1izVDN1UVzNC8rMW1SrZ1y5Bz44iXDrSoKvLNiUCqwRs" ], "script": "base64:BgITCAISAwoBCBIDCgEIEgASAwoBARMABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAHYXNzZXRJZAIsSEhtYUZRcFVvYndLeHpqejRFQ2FCUHRvRjY5a3VqS3dVMmNvemFVelRzZ3YAC3B1enpsZVBvb2xzCQDMCAICIzNONlN0SmRnbVRmQVJzUk5uOVh0NXJEWUVzM3ByNEtHeTF2BQNuaWwBCmdldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIEVW5pdAQBeAUHJG1hdGNoMAgJAO8HAQUEdGhpcwlhdmFpbGFibGUJAPAHAgUEdGhpcwkBBXZhbHVlAQUHYXNzZXRJZAEJdHJ5R2V0SW50AgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoMA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IBQFpCHBheW1lbnRzAAAHYXNzZXRJZAkA2QQBBQdhc3NldElkCQACAQIWaW52YWxpZCB0b2tlbiBhdHRhY2hlZAMJAAACBQtjdXJyZW50UG9vbAIACQACAQIUUG9vbCBub3QgaW5pdGlhbGl6ZWQJAM4IAgkBC3N0YWtlUmVzdWx0AgUEdXNlcgUGYW1vdW50CQEMc3VwcGx5UmVzdWx0AQULY3VycmVudFBvb2wBaQEHdW5zdGFrZQEGYW1vdW50BAR1c2VyCQClCAEIBQFpBmNhbGxlcgQLY3VycmVudFBvb2wJAQl0cnlHZXRTdHICBQR0aGlzAgtjdXJyZW50UG9vbAQCdHgJARZ3aXRoZHJhd0Zyb21QdXp6bGVQb29sAgULY3VycmVudFBvb2wFBmFtb3VudAMJAAACBQJ0eAUCdHgJAM4IAgkBDXVuc3Rha2VSZXN1bHQCBQR1c2VyBQZhbW91bnQJAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyBQZhbW91bnQJANkEAQUHYXNzZXRJZAUDbmlsCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleeFNmT0=", "height": 2341564, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GQUPP2Pu1H1yxzXsa123npXeYvUbjTjNhzSFUA2wkq2U Next: ALUPCoxYdG6XSME6xfy1pfkNe8T9vpxsPtZUjpVU1rwz Diff:
Old | New | Differences | |
---|---|---|---|
73 | 73 | func calculateSRate () = { | |
74 | 74 | let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate") | |
75 | 75 | let stakedAmount = tryGetInt(this, "global_staked") | |
76 | - | let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight") | |
77 | - | let blocks = (height - lastCheckHeight) | |
78 | - | let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8)) | |
79 | 76 | if ((stakedAmount == 0)) | |
80 | 77 | then Scale8 | |
81 | 78 | else { | |
82 | - | let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount)) | |
79 | + | let lastCheckSAmounut = fraction(stakedAmount, lastCheckSRate, Scale8) | |
80 | + | let sRate = fraction(lastCheckSRate, getTotalSuppliedAmount(), lastCheckSAmounut) | |
83 | 81 | if ((Scale8 > sRate)) | |
84 | 82 | then Scale8 | |
85 | 83 | else sRate |
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 | - | let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight") | |
77 | - | let blocks = (height - lastCheckHeight) | |
78 | - | let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8)) | |
79 | 76 | if ((stakedAmount == 0)) | |
80 | 77 | then Scale8 | |
81 | 78 | else { | |
82 | - | let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount)) | |
79 | + | let lastCheckSAmounut = fraction(stakedAmount, lastCheckSRate, Scale8) | |
80 | + | let sRate = fraction(lastCheckSRate, getTotalSuppliedAmount(), lastCheckSAmounut) | |
83 | 81 | if ((Scale8 > sRate)) | |
84 | 82 | then Scale8 | |
85 | 83 | else sRate | |
86 | 84 | } | |
87 | 85 | } | |
88 | 86 | ||
89 | 87 | ||
90 | 88 | func recalcResult (stakedChange) = { | |
91 | 89 | let stakedAmount = tryGetInt(this, "global_staked") | |
92 | 90 | let sRate = calculateSRate() | |
93 | 91 | [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)] | |
94 | 92 | } | |
95 | 93 | ||
96 | 94 | ||
97 | 95 | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
98 | 96 | then throw(("Unknown poolId " + poolId)) | |
99 | 97 | else { | |
100 | 98 | let assetBytes = fromBase58String(assetId) | |
101 | 99 | let balance = getBalance(assetBytes) | |
102 | 100 | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
103 | 101 | if ((inv == inv)) | |
104 | 102 | then [StringEntry("currentPool", poolId)] | |
105 | 103 | else throw("Strict value is not equal to itself.") | |
106 | 104 | } | |
107 | 105 | ||
108 | 106 | ||
109 | 107 | func withdrawResult () = { | |
110 | 108 | let currentPool = tryGetStr(this, "currentPool") | |
111 | 109 | if ((currentPool == "")) | |
112 | 110 | then throw(("Cannot find pool with id " + currentPool)) | |
113 | 111 | else { | |
114 | 112 | let amount = getPuzzlePoolSuppliedAmount(currentPool) | |
115 | 113 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
116 | 114 | if ((tx == tx)) | |
117 | 115 | then tx | |
118 | 116 | else throw("Strict value is not equal to itself.") | |
119 | 117 | } | |
120 | 118 | } | |
121 | 119 | ||
122 | 120 | ||
123 | 121 | func stakeResult (user,amount) = { | |
124 | 122 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
125 | 123 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
126 | 124 | } | |
127 | 125 | ||
128 | 126 | ||
129 | 127 | func unstakeResult (user,amount) = { | |
130 | 128 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
131 | 129 | let userStaked = tryGetInt(this, (user + "_staked")) | |
132 | 130 | let unstakeAmount = if ((sAmount > userStaked)) | |
133 | 131 | then userStaked | |
134 | 132 | else sAmount | |
135 | 133 | (recalcResult(-(sAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))]) | |
136 | 134 | } | |
137 | 135 | ||
138 | 136 | ||
139 | 137 | @Callable(i) | |
140 | 138 | func init (poolId) = { | |
141 | 139 | let currentPool = tryGetStr(this, "currentPool") | |
142 | 140 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
143 | 141 | then throw("Access denied") | |
144 | 142 | else if ((currentPool == "")) | |
145 | 143 | then [StringEntry("currentPool", poolId)] | |
146 | 144 | else nil | |
147 | 145 | } | |
148 | 146 | ||
149 | 147 | ||
150 | 148 | ||
151 | 149 | @Callable(i) | |
152 | 150 | func rebalance (poolId) = { | |
153 | 151 | let currentPool = tryGetStr(this, "currentPool") | |
154 | 152 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
155 | 153 | then throw("Access denied") | |
156 | 154 | else if ((currentPool == poolId)) | |
157 | 155 | then throw(("Already supplied to" + currentPool)) | |
158 | 156 | else { | |
159 | 157 | let withdrawTx = withdrawResult() | |
160 | 158 | if ((withdrawTx == withdrawTx)) | |
161 | 159 | then (supplyResult(poolId) ++ recalcResult(0)) | |
162 | 160 | else throw("Strict value is not equal to itself.") | |
163 | 161 | } | |
164 | 162 | } | |
165 | 163 | ||
166 | 164 | ||
167 | 165 | ||
168 | 166 | @Callable(i) | |
169 | 167 | func stake () = { | |
170 | 168 | let user = toString(i.caller) | |
171 | 169 | let amount = i.payments[0].amount | |
172 | 170 | let currentPool = tryGetStr(this, "currentPool") | |
173 | 171 | if (if ((0 >= amount)) | |
174 | 172 | then true | |
175 | 173 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
176 | 174 | then throw("invalid token attached") | |
177 | 175 | else if ((currentPool == "")) | |
178 | 176 | then throw("Pool not initialized") | |
179 | 177 | else (stakeResult(user, amount) ++ supplyResult(currentPool)) | |
180 | 178 | } | |
181 | 179 | ||
182 | 180 | ||
183 | 181 | ||
184 | 182 | @Callable(i) | |
185 | 183 | func unstake (amount) = { | |
186 | 184 | let user = toString(i.caller) | |
187 | 185 | let currentPool = tryGetStr(this, "currentPool") | |
188 | 186 | let tx = withdrawFromPuzzlePool(currentPool, amount) | |
189 | 187 | if ((tx == tx)) | |
190 | 188 | then (unstakeResult(user, amount) ++ [ScriptTransfer(i.caller, amount, fromBase58String(assetId))]) | |
191 | 189 | else throw("Strict value is not equal to itself.") | |
192 | 190 | } | |
193 | 191 | ||
194 | 192 | ||
195 | 193 | @Verifier(tx) | |
196 | 194 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
197 | 195 |
github/deemru/w8io/169f3d6 27.54 ms ◑