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:BgITCAISAwoBCBIDCgEIEgASAwoBARMABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAHYXNzZXRJZAIsSEhtYUZRcFVvYndLeHpqejRFQ2FCUHRvRjY5a3VqS3dVMmNvemFVelRzZ3YAC3B1enpsZVBvb2xzCQDMCAICIzNONlN0SmRnbVRmQVJzUk5uOVh0NXJEWUVzM3ByNEtHeTF2BQNuaWwBCmdldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIEVW5pdAQBeAUHJG1hdGNoMAgJAO8HAQUEdGhpcwlhdmFpbGFibGUJAPAHAgUEdGhpcwkBBXZhbHVlAQUHYXNzZXRJZAEJdHJ5R2V0SW50AgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoMAIDSW50BA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AQEdXNlcgkApQgBCAUBaQZjYWxsZXIEBmFtb3VudAgJAJEDAggFAWkIcGF5bWVudHMAAAZhbW91bnQEC2N1cnJlbnRQb29sCQEJdHJ5R2V0U3RyAgUEdGhpcwILY3VycmVudFBvb2wDAwkAZwIAAAUGYW1vdW50BgkBAiE9AggJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkCQDZBAEFB2Fzc2V0SWQJAAIBAhZpbnZhbGlkIHRva2VuIGF0dGFjaGVkAwkAAAIFC2N1cnJlbnRQb29sAgAJAAIBAhRQb29sIG5vdCBpbml0aWFsaXplZAkAzggCCQELc3Rha2VSZXN1bHQCBQR1c2VyBQZhbW91bnQJAQxzdXBwbHlSZXN1bHQBBQtjdXJyZW50UG9vbAFpAQd1bnN0YWtlAQZhbW91bnQEBHVzZXIJAKUIAQgFAWkGY2FsbGVyBAtjdXJyZW50UG9vbAkBCXRyeUdldFN0cgIFBHRoaXMCC2N1cnJlbnRQb29sBAJ0eAkBFndpdGhkcmF3RnJvbVB1enpsZVBvb2wCBQtjdXJyZW50UG9vbAUGYW1vdW50AwkAAAIFAnR4BQJ0eAkAzggCCQENdW5zdGFrZVJlc3VsdAIFBHVzZXIFBmFtb3VudAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIFBmFtb3VudAkA2QQBBQdhc3NldElkBQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5U6Ufrw==", "height": 2341477, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9R6erxBzUKkVB27ngEBAaafaT1pWM9JJMBou7jjts4fs Next: GQUPP2Pu1H1yxzXsa123npXeYvUbjTjNhzSFUA2wkq2U Diff:
OldNewDifferences
126126 }
127127
128128
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+
129139 @Callable(i)
130140 func init (poolId) = {
131141 let currentPool = tryGetStr(this, "currentPool")
170180 }
171181
172182
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+
173195 @Verifier(tx)
174196 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
175197
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
4848 func getPuzzlePoolSuppliedAmount (poolId) = {
4949 let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
5050 balance
5151 }
5252
5353
5454 func getTotalSuppliedAmount () = {
5555 let currentPool = tryGetStr(this, "currentPool")
5656 if ((currentPool == ""))
5757 then throw(("Cannot find pool with id " + currentPool))
5858 else getPuzzlePoolSuppliedAmount(currentPool)
5959 }
6060
6161
6262 func withdrawFromPuzzlePool (poolId,amount) = {
6363 let poolAddress = Address(fromBase58String(poolId))
6464 let withdrawTx = if ((amount > 0))
6565 then invoke(poolAddress, "withdraw", [assetId, amount], nil)
6666 else ""
6767 if ((withdrawTx == withdrawTx))
6868 then withdrawTx
6969 else throw("Strict value is not equal to itself.")
7070 }
7171
7272
7373 func calculateSRate () = {
7474 let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate")
7575 let stakedAmount = tryGetInt(this, "global_staked")
7676 let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight")
7777 let blocks = (height - lastCheckHeight)
7878 let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8))
7979 if ((stakedAmount == 0))
8080 then Scale8
8181 else {
8282 let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount))
8383 if ((Scale8 > sRate))
8484 then Scale8
8585 else sRate
8686 }
8787 }
8888
8989
9090 func recalcResult (stakedChange) = {
9191 let stakedAmount = tryGetInt(this, "global_staked")
9292 let sRate = calculateSRate()
9393 [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)]
9494 }
9595
9696
9797 func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit))
9898 then throw(("Unknown poolId " + poolId))
9999 else {
100100 let assetBytes = fromBase58String(assetId)
101101 let balance = getBalance(assetBytes)
102102 let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)])
103103 if ((inv == inv))
104104 then [StringEntry("currentPool", poolId)]
105105 else throw("Strict value is not equal to itself.")
106106 }
107107
108108
109109 func withdrawResult () = {
110110 let currentPool = tryGetStr(this, "currentPool")
111111 if ((currentPool == ""))
112112 then throw(("Cannot find pool with id " + currentPool))
113113 else {
114114 let amount = getPuzzlePoolSuppliedAmount(currentPool)
115115 let tx = withdrawFromPuzzlePool(currentPool, amount)
116116 if ((tx == tx))
117117 then tx
118118 else throw("Strict value is not equal to itself.")
119119 }
120120 }
121121
122122
123123 func stakeResult (user,amount) = {
124124 let sAmount = fraction(amount, Scale8, calculateSRate())
125125 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
126126 }
127127
128128
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+
129139 @Callable(i)
130140 func init (poolId) = {
131141 let currentPool = tryGetStr(this, "currentPool")
132142 if ((indexOf(validators, toString(i.caller)) == unit))
133143 then throw("Access denied")
134144 else if ((currentPool == ""))
135145 then [StringEntry("currentPool", poolId)]
136146 else nil
137147 }
138148
139149
140150
141151 @Callable(i)
142152 func rebalance (poolId) = {
143153 let currentPool = tryGetStr(this, "currentPool")
144154 if ((indexOf(validators, toString(i.caller)) == unit))
145155 then throw("Access denied")
146156 else if ((currentPool == poolId))
147157 then throw(("Already supplied to" + currentPool))
148158 else {
149159 let withdrawTx = withdrawResult()
150160 if ((withdrawTx == withdrawTx))
151161 then (supplyResult(poolId) ++ recalcResult(0))
152162 else throw("Strict value is not equal to itself.")
153163 }
154164 }
155165
156166
157167
158168 @Callable(i)
159169 func stake () = {
160170 let user = toString(i.caller)
161171 let amount = i.payments[0].amount
162172 let currentPool = tryGetStr(this, "currentPool")
163173 if (if ((0 >= amount))
164174 then true
165175 else (i.payments[0].assetId != fromBase58String(assetId)))
166176 then throw("invalid token attached")
167177 else if ((currentPool == ""))
168178 then throw("Pool not initialized")
169179 else (stakeResult(user, amount) ++ supplyResult(currentPool))
170180 }
171181
172182
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+
173195 @Verifier(tx)
174196 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
175197

github/deemru/w8io/169f3d6 
30.10 ms