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:BgITCAISAwoBCBIDCgEIEgASAwoBARMABlNjYWxlNgDAhD0ABlNjYWxlOACAwtcvAAdTY2FsZTE2CQBoAgUGU2NhbGU4BQZTY2FsZTgACnZhbGlkYXRvcnMJAMwIAgIjM05BbXFHanhSQlJQb1JIWlVVcXZoaU5TNmF4bkdwaW5MSEMFA25pbAAHYXNzZXRJZAIsSEhtYUZRcFVvYndLeHpqejRFQ2FCUHRvRjY5a3VqS3dVMmNvemFVelRzZ3YAC3B1enpsZVBvb2xzCQDMCAICIzNONlN0SmRnbVRmQVJzUk5uOVh0NXJEWUVzM3ByNEtHeTF2BQNuaWwBCmdldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIEVW5pdAQBeAUHJG1hdGNoMAgJAO8HAQUEdGhpcwlhdmFpbGFibGUJAPAHAgUEdGhpcwkBBXZhbHVlAQUHYXNzZXRJZAEJdHJ5R2V0SW50AgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoM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IIBQFpCHBheW1lbnRzAAAHYXNzZXRJZAkA2QQBBQdhc3NldElkCQACAQIWaW52YWxpZCB0b2tlbiBhdHRhY2hlZAMJAAACBQtjdXJyZW50UG9vbAIACQACAQIUUG9vbCBub3QgaW5pdGlhbGl6ZWQJAM4IAgkBC3N0YWtlUmVzdWx0AgUEdXNlcgUGYW1vdW50CQEMc3VwcGx5UmVzdWx0AQULY3VycmVudFBvb2wBaQEHdW5zdGFrZQEGYW1vdW50BAR1c2VyCQClCAEIBQFpBmNhbGxlcgQLY3VycmVudFBvb2wJAQl0cnlHZXRTdHICBQR0aGlzAgtjdXJyZW50UG9vbAQCdHgJARZ3aXRoZHJhd0Zyb21QdXp6bGVQb29sAgULY3VycmVudFBvb2wFBmFtb3VudAMJAAACBQJ0eAUCdHgJAM4IAgkBDXVuc3Rha2VSZXN1bHQCBQR1c2VyBQZhbW91bnQJAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyBQZhbW91bnQJANkEAQUHYXNzZXRJZAUDbmlsCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleeFNmT0=", "height": 2341564, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GQUPP2Pu1H1yxzXsa123npXeYvUbjTjNhzSFUA2wkq2U Next: ALUPCoxYdG6XSME6xfy1pfkNe8T9vpxsPtZUjpVU1rwz Diff:
OldNewDifferences
7373 func calculateSRate () = {
7474 let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate")
7575 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))
7976 if ((stakedAmount == 0))
8077 then Scale8
8178 else {
82- let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount))
79+ let lastCheckSAmounut = fraction(stakedAmount, lastCheckSRate, Scale8)
80+ let sRate = fraction(lastCheckSRate, getTotalSuppliedAmount(), lastCheckSAmounut)
8381 if ((Scale8 > sRate))
8482 then Scale8
8583 else sRate
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")
76- let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight")
77- let blocks = (height - lastCheckHeight)
78- let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8))
7976 if ((stakedAmount == 0))
8077 then Scale8
8178 else {
82- let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount))
79+ let lastCheckSAmounut = fraction(stakedAmount, lastCheckSRate, Scale8)
80+ let sRate = fraction(lastCheckSRate, getTotalSuppliedAmount(), lastCheckSAmounut)
8381 if ((Scale8 > sRate))
8482 then Scale8
8583 else sRate
8684 }
8785 }
8886
8987
9088 func recalcResult (stakedChange) = {
9189 let stakedAmount = tryGetInt(this, "global_staked")
9290 let sRate = calculateSRate()
9391 [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)]
9492 }
9593
9694
9795 func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit))
9896 then throw(("Unknown poolId " + poolId))
9997 else {
10098 let assetBytes = fromBase58String(assetId)
10199 let balance = getBalance(assetBytes)
102100 let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)])
103101 if ((inv == inv))
104102 then [StringEntry("currentPool", poolId)]
105103 else throw("Strict value is not equal to itself.")
106104 }
107105
108106
109107 func withdrawResult () = {
110108 let currentPool = tryGetStr(this, "currentPool")
111109 if ((currentPool == ""))
112110 then throw(("Cannot find pool with id " + currentPool))
113111 else {
114112 let amount = getPuzzlePoolSuppliedAmount(currentPool)
115113 let tx = withdrawFromPuzzlePool(currentPool, amount)
116114 if ((tx == tx))
117115 then tx
118116 else throw("Strict value is not equal to itself.")
119117 }
120118 }
121119
122120
123121 func stakeResult (user,amount) = {
124122 let sAmount = fraction(amount, Scale8, calculateSRate())
125123 (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))])
126124 }
127125
128126
129127 func unstakeResult (user,amount) = {
130128 let sAmount = fraction(amount, Scale8, calculateSRate())
131129 let userStaked = tryGetInt(this, (user + "_staked"))
132130 let unstakeAmount = if ((sAmount > userStaked))
133131 then userStaked
134132 else sAmount
135133 (recalcResult(-(sAmount)) ++ [IntegerEntry((user + "_staked"), (userStaked - unstakeAmount))])
136134 }
137135
138136
139137 @Callable(i)
140138 func init (poolId) = {
141139 let currentPool = tryGetStr(this, "currentPool")
142140 if ((indexOf(validators, toString(i.caller)) == unit))
143141 then throw("Access denied")
144142 else if ((currentPool == ""))
145143 then [StringEntry("currentPool", poolId)]
146144 else nil
147145 }
148146
149147
150148
151149 @Callable(i)
152150 func rebalance (poolId) = {
153151 let currentPool = tryGetStr(this, "currentPool")
154152 if ((indexOf(validators, toString(i.caller)) == unit))
155153 then throw("Access denied")
156154 else if ((currentPool == poolId))
157155 then throw(("Already supplied to" + currentPool))
158156 else {
159157 let withdrawTx = withdrawResult()
160158 if ((withdrawTx == withdrawTx))
161159 then (supplyResult(poolId) ++ recalcResult(0))
162160 else throw("Strict value is not equal to itself.")
163161 }
164162 }
165163
166164
167165
168166 @Callable(i)
169167 func stake () = {
170168 let user = toString(i.caller)
171169 let amount = i.payments[0].amount
172170 let currentPool = tryGetStr(this, "currentPool")
173171 if (if ((0 >= amount))
174172 then true
175173 else (i.payments[0].assetId != fromBase58String(assetId)))
176174 then throw("invalid token attached")
177175 else if ((currentPool == ""))
178176 then throw("Pool not initialized")
179177 else (stakeResult(user, amount) ++ supplyResult(currentPool))
180178 }
181179
182180
183181
184182 @Callable(i)
185183 func unstake (amount) = {
186184 let user = toString(i.caller)
187185 let currentPool = tryGetStr(this, "currentPool")
188186 let tx = withdrawFromPuzzlePool(currentPool, amount)
189187 if ((tx == tx))
190188 then (unstakeResult(user, amount) ++ [ScriptTransfer(i.caller, amount, fromBase58String(assetId))])
191189 else throw("Strict value is not equal to itself.")
192190 }
193191
194192
195193 @Verifier(tx)
196194 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
197195

github/deemru/w8io/169f3d6 
27.54 ms