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:BgIJCAISAwoBCBIAEQAGU2NhbGU2AMCEPQAGU2NhbGU4AIDC1y8AB1NjYWxlMTYJAGgCBQZTY2FsZTgFBlNjYWxlOAAKdmFsaWRhdG9ycwkAzAgCAiMzTkFtcUdqeFJCUlBvUkhaVVVxdmhpTlM2YXhuR3BpbkxIQwUDbmlsAAdhc3NldElkAixISG1hRlFwVW9id0t4emp6NEVDYUJQdG9GNjlrdWpLd1UyY296YVV6VHNndgALcHV6emxlUG9vbHMJAMwIAgIjM042U3RKZGdtVGZBUnNSTm45WHQ1ckRZRXMzcHI0S0d5MXYFA25pbAEKZ2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgRVbml0BAF4BQckbWF0Y2gwCAkA7wcBBQR0aGlzCWF2YWlsYWJsZQkA8AcCBQR0aGlzCQEFdmFsdWUBBQdhc3NldElkAQl0cnlHZXRJbnQCB2FkZHJlc3MDa2V5BAckbWF0Y2gwCQCaCAIFB2FkZHJlc3MFA2tleQMJAAECBQckbWF0Y2gwAgNJbnQEAWIFByRtYX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seVJlc3VsdAEFBnBvb2xJZAkBDHJlY2FsY1Jlc3VsdAEAAAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgFpAQVzdGFrZQAEBHVzZXIJAKUIAQgFAWkGY2FsbGVyBAZhbW91bnQICQCRAwIIBQFpCHBheW1lbnRzAAAGYW1vdW50BAtjdXJyZW50UG9vbAkBCXRyeUdldFN0cgIFBHRoaXMCC2N1cnJlbnRQb29sAwMJAGcCAAAFBmFtb3VudAYJAQIhPQIICQCRAwIIBQFpCHBheW1lbnRzAAAHYXNzZXRJZAkA2QQBBQdhc3NldElkCQACAQIWaW52YWxpZCB0b2tlbiBhdHRhY2hlZAMJAAACBQtjdXJyZW50UG9vbAIACQACAQIUUG9vbCBub3QgaW5pdGlhbGl6ZWQJAM4IAgkBC3N0YWtlUmVzdWx0AgUEdXNlcgUGYW1vdW50CQEMc3VwcGx5UmVzdWx0AQULY3VycmVudFBvb2wBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5hxjZsA==", "height": 2340167, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GJgHWHssEwXM3uEng789AxfCXnvBHtpa3oYkfh164TtW Next: ALtUDyXosYHwARe1G5sRnpKYLVNDfYnUXRkQW9Ky5wH6 Diff:
Old | New | Differences | |
---|---|---|---|
45 | 45 | } | |
46 | 46 | ||
47 | 47 | ||
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 | + | } | |
52 | 54 | ||
53 | 55 | ||
54 | 56 | func getTotalSuppliedAmount () = { | |
106 | 108 | } | |
107 | 109 | ||
108 | 110 | ||
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 | - | ||
123 | 111 | func stakeResult (user,amount) = { | |
124 | 112 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
125 | 113 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
134 | 122 | else if ((currentPool == poolId)) | |
135 | 123 | then throw(("Already supplied to" + currentPool)) | |
136 | 124 | 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)) | |
139 | 130 | then (supplyResult(poolId) ++ recalcResult(0)) | |
140 | 131 | else throw("Strict value is not equal to itself.") | |
141 | 132 | } |
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 | - | 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 | + | } | |
52 | 54 | ||
53 | 55 | ||
54 | 56 | func getTotalSuppliedAmount () = { | |
55 | 57 | let currentPool = tryGetStr(this, "currentPool") | |
56 | 58 | if ((currentPool == "")) | |
57 | 59 | then throw(("Cannot find pool with id " + currentPool)) | |
58 | 60 | else getPuzzlePoolSuppliedAmount(currentPool) | |
59 | 61 | } | |
60 | 62 | ||
61 | 63 | ||
62 | 64 | func withdrawFromPuzzlePool (poolId,amount) = { | |
63 | 65 | let poolAddress = Address(fromBase58String(poolId)) | |
64 | 66 | let withdrawTx = if ((amount > 0)) | |
65 | 67 | then invoke(poolAddress, "withdraw", [assetId, amount], nil) | |
66 | 68 | else "" | |
67 | 69 | if ((withdrawTx == withdrawTx)) | |
68 | 70 | then withdrawTx | |
69 | 71 | else throw("Strict value is not equal to itself.") | |
70 | 72 | } | |
71 | 73 | ||
72 | 74 | ||
73 | 75 | func calculateSRate () = { | |
74 | 76 | let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate") | |
75 | 77 | let stakedAmount = tryGetInt(this, "global_staked") | |
76 | 78 | let lastCheckHeight = tryGetInt(this, "global_lastCheckSRateHeight") | |
77 | 79 | let blocks = (height - lastCheckHeight) | |
78 | 80 | let stakingEmission = (getTotalSuppliedAmount() - fraction(stakedAmount, lastCheckSRate, Scale8)) | |
79 | 81 | if ((stakedAmount == 0)) | |
80 | 82 | then Scale8 | |
81 | 83 | else { | |
82 | 84 | let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount)) | |
83 | 85 | if ((Scale8 > sRate)) | |
84 | 86 | then Scale8 | |
85 | 87 | else sRate | |
86 | 88 | } | |
87 | 89 | } | |
88 | 90 | ||
89 | 91 | ||
90 | 92 | func recalcResult (stakedChange) = { | |
91 | 93 | let stakedAmount = tryGetInt(this, "global_staked") | |
92 | 94 | let sRate = calculateSRate() | |
93 | 95 | [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)] | |
94 | 96 | } | |
95 | 97 | ||
96 | 98 | ||
97 | 99 | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
98 | 100 | then throw(("Unknown poolId " + poolId)) | |
99 | 101 | else { | |
100 | 102 | let assetBytes = fromBase58String(assetId) | |
101 | 103 | let balance = getBalance(assetBytes) | |
102 | 104 | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
103 | 105 | if ((inv == inv)) | |
104 | 106 | then [StringEntry("currentPool", poolId)] | |
105 | 107 | else throw("Strict value is not equal to itself.") | |
106 | 108 | } | |
107 | 109 | ||
108 | 110 | ||
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 | - | ||
123 | 111 | func stakeResult (user,amount) = { | |
124 | 112 | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
125 | 113 | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
126 | 114 | } | |
127 | 115 | ||
128 | 116 | ||
129 | 117 | @Callable(i) | |
130 | 118 | func rebalance (poolId) = { | |
131 | 119 | let currentPool = tryGetStr(this, "currentPool") | |
132 | 120 | if ((indexOf(validators, toString(i.caller)) == unit)) | |
133 | 121 | then throw("Access denied") | |
134 | 122 | else if ((currentPool == poolId)) | |
135 | 123 | then throw(("Already supplied to" + currentPool)) | |
136 | 124 | 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)) | |
139 | 130 | then (supplyResult(poolId) ++ recalcResult(0)) | |
140 | 131 | else throw("Strict value is not equal to itself.") | |
141 | 132 | } | |
142 | 133 | } | |
143 | 134 | ||
144 | 135 | ||
145 | 136 | ||
146 | 137 | @Callable(i) | |
147 | 138 | func stake () = { | |
148 | 139 | let user = toString(i.caller) | |
149 | 140 | let amount = i.payments[0].amount | |
150 | 141 | let currentPool = tryGetStr(this, "currentPool") | |
151 | 142 | if (if ((0 >= amount)) | |
152 | 143 | then true | |
153 | 144 | else (i.payments[0].assetId != fromBase58String(assetId))) | |
154 | 145 | then throw("invalid token attached") | |
155 | 146 | else if ((currentPool == "")) | |
156 | 147 | then throw("Pool not initialized") | |
157 | 148 | else (stakeResult(user, amount) ++ supplyResult(currentPool)) | |
158 | 149 | } | |
159 | 150 | ||
160 | 151 | ||
161 | 152 | @Verifier(tx) | |
162 | 153 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
163 | 154 |
github/deemru/w8io/169f3d6 27.52 ms ◑