tx · ALtUDyXosYHwARe1G5sRnpKYLVNDfYnUXRkQW9Ky5wH6

3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh:  -0.00800000 Waves

2022.11.30 20:59 [2340169] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves

{ "type": 13, "id": "ALtUDyXosYHwARe1G5sRnpKYLVNDfYnUXRkQW9Ky5wH6", "fee": 800000, "feeAssetId": null, "timestamp": 1669831201779, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "5YnD4PU9JcKb4KJXbnBY6Ror1hxSLmkvkfqrXdipvjcWLgELAgDhqWcXKJTamu5XoQKpU3MPQpa9rA8dFWQZnvXa" ], "script": "base64:BgIOCAISAwoBCBIDCgEIEgASAAZTY2FsZTYAwIQ9AAZTY2FsZTgAgMLXLwAHU2NhbGUxNgkAaAIFBlNjYWxlOAUGU2NhbGU4AAp2YWxpZGF0b3JzCQDMCAICIzNOQW1xR2p4UkJSUG9SSFpVVXF2aGlOUzZheG5HcGluTEhDBQNuaWwAB2Fzc2V0SWQCLEhIbWFGUXBVb2J3S3h6ano0RUNhQlB0b0Y2OWt1akt3VTJjb3phVXpUc2d2AAtwdXp6bGVQb29scwkAzAgCAiMzTjZTdEpkZ21UZkFSc1JObjlYdDVyRFlFczNwcjRLR3kxdgUDbmlsAQpnZXRCYWxhbmNlAQdhc3NldElkBAckbWF0Y2gwBQdhc3NldElkAwkAAQIFByRtYXRjaDACBFVuaXQEAXgFByRtYXRjaDAICQDvBwEFBHRoaXMJYXZhaWxhYmxlCQDwBwIFBHRoaXMJAQV2YWx1ZQEFB2Fzc2V0SWQBCXRyeUdldEludAIHYWRkcmVzcwNrZXkEByRtYXRjaDAJAJoIAgUHYWRkcmVzcwUDa2V5AwkAAQIFByRtYXRjaDACA0ludA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FBvb2wBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5dzrfdw==", "height": 2340169, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: G3MuSEZ7UCSPQw5t9jCEnG9uKotau9x64PZjbQtw6Po Next: 9R6erxBzUKkVB27ngEBAaafaT1pWM9JJMBou7jjts4fs Diff:
OldNewDifferences
4545 }
4646
4747
48-func getPuzzlePoolSuppliedAmount (poolId) = if ((poolId == ""))
49- then 0
50- else {
51- let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
52- balance
53- }
48+func getPuzzlePoolSuppliedAmount (poolId) = {
49+ let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
50+ balance
51+ }
5452
5553
5654 func getTotalSuppliedAmount () = {
108106 }
109107
110108
109+func withdrawResult () = {
110+ let currentPool = tryGetStr(this, "currentPool")
111+ if ((currentPool == ""))
112+ then throw(("Cannot find pool with id " + currentPool))
113+ else {
114+ let amount = getPuzzlePoolSuppliedAmount(currentPool)
115+ let tx = withdrawFromPuzzlePool(currentPool, amount)
116+ if ((tx == tx))
117+ then tx
118+ else throw("Strict value is not equal to itself.")
119+ }
120+ }
121+
122+
111123 func stakeResult (user,amount) = {
112124 let sAmount = fraction(amount, Scale8, calculateSRate())
113125 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
114126 }
127+
128+
129+@Callable(i)
130+func init (poolId) = {
131+ let currentPool = tryGetStr(this, "currentPool")
132+ if ((indexOf(validators, toString(i.caller)) == unit))
133+ then throw("Access denied")
134+ else if ((currentPool == ""))
135+ then [StringEntry("currentPool", poolId)]
136+ else nil
137+ }
138+
115139
116140
117141 @Callable(i)
122146 else if ((currentPool == poolId))
123147 then throw(("Already supplied to" + currentPool))
124148 else {
125- let amount = getPuzzlePoolSuppliedAmount(currentPool)
126- let tx = if ((amount > 0))
127- then withdrawFromPuzzlePool(currentPool, amount)
128- else ""
129- if ((tx == tx))
149+ let withdrawTx = withdrawResult()
150+ if ((withdrawTx == withdrawTx))
130151 then (supplyResult(poolId) ++ recalcResult(0))
131152 else throw("Strict value is not equal to itself.")
132153 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let Scale6 = 1000000
55
66 let Scale8 = 100000000
77
88 let Scale16 = (Scale8 * Scale8)
99
1010 let validators = ["3NAmqGjxRBRPoRHZUUqvhiNS6axnGpinLHC"]
1111
1212 let assetId = "HHmaFQpUobwKxzjz4ECaBPtoF69kujKwU2cozaUzTsgv"
1313
1414 let puzzlePools = ["3N6StJdgmTfARsRNn9Xt5rDYEs3pr4KGy1v"]
1515
1616 func getBalance (assetId) = match assetId {
1717 case x: Unit =>
1818 wavesBalance(this).available
1919 case _ =>
2020 assetBalance(this, value(assetId))
2121 }
2222
2323
2424 func tryGetInt (address,key) = match getInteger(address, key) {
2525 case b: Int =>
2626 b
2727 case _ =>
2828 0
2929 }
3030
3131
3232 func tryGetStr (address,key) = match getString(address, key) {
3333 case b: String =>
3434 b
3535 case _ =>
3636 ""
3737 }
3838
3939
4040 func getAssetString (assetId) = match assetId {
4141 case b: ByteVector =>
4242 toBase58String(b)
4343 case _ =>
4444 "WAVES"
4545 }
4646
4747
48-func getPuzzlePoolSuppliedAmount (poolId) = if ((poolId == ""))
49- then 0
50- else {
51- let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
52- balance
53- }
48+func getPuzzlePoolSuppliedAmount (poolId) = {
49+ let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
50+ balance
51+ }
5452
5553
5654 func getTotalSuppliedAmount () = {
5755 let currentPool = tryGetStr(this, "currentPool")
5856 if ((currentPool == ""))
5957 then throw(("Cannot find pool with id " + currentPool))
6058 else getPuzzlePoolSuppliedAmount(currentPool)
6159 }
6260
6361
6462 func withdrawFromPuzzlePool (poolId,amount) = {
6563 let poolAddress = Address(fromBase58String(poolId))
6664 let withdrawTx = if ((amount > 0))
6765 then invoke(poolAddress, "withdraw", [assetId, amount], nil)
6866 else ""
6967 if ((withdrawTx == withdrawTx))
7068 then withdrawTx
7169 else throw("Strict value is not equal to itself.")
7270 }
7371
7472
7573 func calculateSRate () = {
7674 let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate")
7775 let stakedAmount = tryGetInt(this, "global_staked")
7876 let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight")
7977 let blocks = (height - lastCheckHeight)
8078 let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8))
8179 if ((stakedAmount == 0))
8280 then Scale8
8381 else {
8482 let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount))
8583 if ((Scale8 > sRate))
8684 then Scale8
8785 else sRate
8886 }
8987 }
9088
9189
9290 func recalcResult (stakedChange) = {
9391 let stakedAmount = tryGetInt(this, "global_staked")
9492 let sRate = calculateSRate()
9593 [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)]
9694 }
9795
9896
9997 func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit))
10098 then throw(("Unknown poolId " + poolId))
10199 else {
102100 let assetBytes = fromBase58String(assetId)
103101 let balance = getBalance(assetBytes)
104102 let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)])
105103 if ((inv == inv))
106104 then [StringEntry("currentPool", poolId)]
107105 else throw("Strict value is not equal to itself.")
108106 }
109107
110108
109+func withdrawResult () = {
110+ let currentPool = tryGetStr(this, "currentPool")
111+ if ((currentPool == ""))
112+ then throw(("Cannot find pool with id " + currentPool))
113+ else {
114+ let amount = getPuzzlePoolSuppliedAmount(currentPool)
115+ let tx = withdrawFromPuzzlePool(currentPool, amount)
116+ if ((tx == tx))
117+ then tx
118+ else throw("Strict value is not equal to itself.")
119+ }
120+ }
121+
122+
111123 func stakeResult (user,amount) = {
112124 let sAmount = fraction(amount, Scale8, calculateSRate())
113125 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
114126 }
127+
128+
129+@Callable(i)
130+func init (poolId) = {
131+ let currentPool = tryGetStr(this, "currentPool")
132+ if ((indexOf(validators, toString(i.caller)) == unit))
133+ then throw("Access denied")
134+ else if ((currentPool == ""))
135+ then [StringEntry("currentPool", poolId)]
136+ else nil
137+ }
138+
115139
116140
117141 @Callable(i)
118142 func rebalance (poolId) = {
119143 let currentPool = tryGetStr(this, "currentPool")
120144 if ((indexOf(validators, toString(i.caller)) == unit))
121145 then throw("Access denied")
122146 else if ((currentPool == poolId))
123147 then throw(("Already supplied to" + currentPool))
124148 else {
125- let amount = getPuzzlePoolSuppliedAmount(currentPool)
126- let tx = if ((amount > 0))
127- then withdrawFromPuzzlePool(currentPool, amount)
128- else ""
129- if ((tx == tx))
149+ let withdrawTx = withdrawResult()
150+ if ((withdrawTx == withdrawTx))
130151 then (supplyResult(poolId) ++ recalcResult(0))
131152 else throw("Strict value is not equal to itself.")
132153 }
133154 }
134155
135156
136157
137158 @Callable(i)
138159 func stake () = {
139160 let user = toString(i.caller)
140161 let amount = i.payments[0].amount
141162 let currentPool = tryGetStr(this, "currentPool")
142163 if (if ((0 >= amount))
143164 then true
144165 else (i.payments[0].assetId != fromBase58String(assetId)))
145166 then throw("invalid token attached")
146167 else if ((currentPool == ""))
147168 then throw("Pool not initialized")
148169 else (stakeResult(user, amount) ++ supplyResult(currentPool))
149170 }
150171
151172
152173 @Verifier(tx)
153174 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
154175

github/deemru/w8io/169f3d6 
24.92 ms