tx · G3MuSEZ7UCSPQw5t9jCEnG9uKotau9x64PZjbQtw6Po

3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh:  -0.00800000 Waves

2022.11.30 20:56 [2340167] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves

{ "type": 13, "id": "G3MuSEZ7UCSPQw5t9jCEnG9uKotau9x64PZjbQtw6Po", "fee": 800000, "feeAssetId": null, "timestamp": 1669831051588, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "2Ychjh8My6kjQrMNEPVauKEv1mnRhReZ2x2ZCACeqBVuqRtqkunnfTp2AWp4pNBb2qRPnSpwpvYqfg3DrQBsHT6d" ], "script": "base64:BgIJCAISAwoBCBIAEQAGU2NhbGU2AMCEPQAGU2NhbGU4AIDC1y8AB1NjYWxlMTYJAGgCBQZTY2FsZTgFBlNjYWxlOAAKdmFsaWRhdG9ycwkAzAgCAiMzTkFtcUdqeFJCUlBvUkhaVVVxdmhpTlM2YXhuR3BpbkxIQwUDbmlsAAdhc3NldElkAixISG1hRlFwVW9id0t4emp6NEVDYUJQdG9GNjlrdWpLd1UyY296YVV6VHNndgALcHV6emxlUG9vbHMJAMwIAgIjM042U3RKZGdtVGZBUnNSTm45WHQ1ckRZRXMzcHI0S0d5MXYFA25pbAEKZ2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgRVbml0BAF4BQckbWF0Y2gwCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQkA8AcCBQR0aGlzCQEFdmFsdWUBBQdhc3NldElkAQl0cnlHZXRJbnQCB2FkZHJlc3MDa2V5BAckbWF0Y2gwCQCaCAIFB2FkZHJlc3MFA2tleQMJAAECBQckbWF0Y2gwAgNJbnQEAWIFByRtY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BseVJlc3VsdAEFBnBvb2xJZAkBDHJlY2FsY1Jlc3VsdAEAAAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpAQVzdGFrZQAEBHVzZXIJAKUIAQgFAWkGY2FsbGVyBAZhbW91bnQICQCRAwIIBQFpCHBheW1lbnRzAAAGYW1vdW50BAtjdXJyZW50UG9vbAkBCXRyeUdldFN0cgIFBHRoaXMCC2N1cnJlbnRQb29sAwMJAGcCAAAFBmFtb3VudAYJAQIhPQIICQCRAwIIBQFpCHBheW1lbnRzAAAHYXNzZXRJZAkA2QQBBQdhc3NldElkCQACAQIWaW52YWxpZCB0b2tlbiBhdHRhY2hlZAMJAAACBQtjdXJyZW50UG9vbAIACQACAQIUUG9vbCBub3QgaW5pdGlhbGl6ZWQJAM4IAgkBC3N0YWtlUmVzdWx0AgUEdXNlcgUGYW1vdW50CQEMc3VwcGx5UmVzdWx0AQULY3VycmVudFBvb2wBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5hxjZsA==", "height": 2340167, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GJgHWHssEwXM3uEng789AxfCXnvBHtpa3oYkfh164TtW Next: ALtUDyXosYHwARe1G5sRnpKYLVNDfYnUXRkQW9Ky5wH6 Diff:
OldNewDifferences
4545 }
4646
4747
48-func getPuzzlePoolSuppliedAmount (poolId) = {
49- let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
50- balance
51- }
48+func getPuzzlePoolSuppliedAmount (poolId) = if ((poolId == ""))
49+ then 0
50+ else {
51+ let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
52+ balance
53+ }
5254
5355
5456 func getTotalSuppliedAmount () = {
106108 }
107109
108110
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-
123111 func stakeResult (user,amount) = {
124112 let sAmount = fraction(amount, Scale8, calculateSRate())
125113 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
134122 else if ((currentPool == poolId))
135123 then throw(("Already supplied to" + currentPool))
136124 else {
137- let withdrawTx = withdrawResult()
138- if ((withdrawTx == withdrawTx))
125+ let amount = getPuzzlePoolSuppliedAmount(currentPool)
126+ let tx = if ((amount > 0))
127+ then withdrawFromPuzzlePool(currentPool, amount)
128+ else ""
129+ if ((tx == tx))
139130 then (supplyResult(poolId) ++ recalcResult(0))
140131 else throw("Strict value is not equal to itself.")
141132 }
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) = {
49- let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
50- balance
51- }
48+func getPuzzlePoolSuppliedAmount (poolId) = if ((poolId == ""))
49+ then 0
50+ else {
51+ let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId))
52+ balance
53+ }
5254
5355
5456 func getTotalSuppliedAmount () = {
5557 let currentPool = tryGetStr(this, "currentPool")
5658 if ((currentPool == ""))
5759 then throw(("Cannot find pool with id " + currentPool))
5860 else getPuzzlePoolSuppliedAmount(currentPool)
5961 }
6062
6163
6264 func withdrawFromPuzzlePool (poolId,amount) = {
6365 let poolAddress = Address(fromBase58String(poolId))
6466 let withdrawTx = if ((amount > 0))
6567 then invoke(poolAddress, "withdraw", [assetId, amount], nil)
6668 else ""
6769 if ((withdrawTx == withdrawTx))
6870 then withdrawTx
6971 else throw("Strict value is not equal to itself.")
7072 }
7173
7274
7375 func calculateSRate () = {
7476 let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate")
7577 let stakedAmount = tryGetInt(this, "global_staked")
7678 let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight")
7779 let blocks = (height - lastCheckHeight)
7880 let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8))
7981 if ((stakedAmount == 0))
8082 then Scale8
8183 else {
8284 let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount))
8385 if ((Scale8 > sRate))
8486 then Scale8
8587 else sRate
8688 }
8789 }
8890
8991
9092 func recalcResult (stakedChange) = {
9193 let stakedAmount = tryGetInt(this, "global_staked")
9294 let sRate = calculateSRate()
9395 [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)]
9496 }
9597
9698
9799 func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit))
98100 then throw(("Unknown poolId " + poolId))
99101 else {
100102 let assetBytes = fromBase58String(assetId)
101103 let balance = getBalance(assetBytes)
102104 let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)])
103105 if ((inv == inv))
104106 then [StringEntry("currentPool", poolId)]
105107 else throw("Strict value is not equal to itself.")
106108 }
107109
108110
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-
123111 func stakeResult (user,amount) = {
124112 let sAmount = fraction(amount, Scale8, calculateSRate())
125113 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
126114 }
127115
128116
129117 @Callable(i)
130118 func rebalance (poolId) = {
131119 let currentPool = tryGetStr(this, "currentPool")
132120 if ((indexOf(validators, toString(i.caller)) == unit))
133121 then throw("Access denied")
134122 else if ((currentPool == poolId))
135123 then throw(("Already supplied to" + currentPool))
136124 else {
137- let withdrawTx = withdrawResult()
138- if ((withdrawTx == withdrawTx))
125+ let amount = getPuzzlePoolSuppliedAmount(currentPool)
126+ let tx = if ((amount > 0))
127+ then withdrawFromPuzzlePool(currentPool, amount)
128+ else ""
129+ if ((tx == tx))
139130 then (supplyResult(poolId) ++ recalcResult(0))
140131 else throw("Strict value is not equal to itself.")
141132 }
142133 }
143134
144135
145136
146137 @Callable(i)
147138 func stake () = {
148139 let user = toString(i.caller)
149140 let amount = i.payments[0].amount
150141 let currentPool = tryGetStr(this, "currentPool")
151142 if (if ((0 >= amount))
152143 then true
153144 else (i.payments[0].assetId != fromBase58String(assetId)))
154145 then throw("invalid token attached")
155146 else if ((currentPool == ""))
156147 then throw("Pool not initialized")
157148 else (stakeResult(user, amount) ++ supplyResult(currentPool))
158149 }
159150
160151
161152 @Verifier(tx)
162153 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
163154

github/deemru/w8io/169f3d6 
41.65 ms