tx · 9nFkN9cAaP6JP4nE4HasH9i22D1swvkewz8zFJKLStZS 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh: -0.00800000 Waves 2022.11.30 20:32 [2340138] smart account 3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh > SELF 0.00000000 Waves
{ "type": 13, "id": "9nFkN9cAaP6JP4nE4HasH9i22D1swvkewz8zFJKLStZS", "fee": 800000, "feeAssetId": null, "timestamp": 1669829531822, "version": 2, "chainId": 84, "sender": "3MwLW8P5yh5T2xML9QqFuVxkVkm9RXqnzXh", "senderPublicKey": "HscGVyJG5M3NMHWKfQbucCBsFLGPi8VmTxTAmcBbaWTa", "proofs": [ "5rYbrXRd3njLwbQqkSd1fiXCbNVwp5zDQokXn8biPBwmDpoyKZRChnMDRxHyQvTQJqTQK9RmDCjjSEus2fuE55GU" ], "script": "base64:BgIJCAISAwoBCBIAEgAGU2NhbGU2AMCEPQAGU2NhbGU4AIDC1y8AB1NjYWxlMTYJAGgCBQZTY2FsZTgFBlNjYWxlOAAKdmFsaWRhdG9ycwkAzAgCAgAFA25pbAAHYXNzZXRJZAIsSEhtYUZRcFVvYndLeHpqejRFQ2FCUHRvRjY5a3VqS3dVMmNvemFVelRzZ3YAC3B1enpsZVBvb2xzCQDMCAICIzNONlN0SmRnbVRmQVJzUk5uOVh0NXJEWUVzM3ByNEtHeTF2BQNuaWwBCmdldEJhbGFuY2UBB2Fzc2V0SWQEByRtYXRjaDAFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIEVW5pdAQBeAUHJG1hdGNoMAgJAO8HAQUEdGhpcwlhdmFpbGFibGUJAPAHAgUEdGhpcwkBBXZhbHVlAQUHYXNzZXRJZAEJdHJ5R2V0SW50AgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoMAIDSW50BAFiBQckbWF0Y2gwBQFiAAABCXRyeUdldFN0cgIHYWRkcmVzcwNrZXkEByR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BQFpBmNhbGxlcgUEdW5pdAkAAgECDUFjY2VzcyBkZW5pZWQDCQAAAgULY3VycmVudFBvb2wFBnBvb2xJZAkAAgEJAKwCAgITQWxyZWFkeSBzdXBwbGllZCB0bwULY3VycmVudFBvb2wECndpdGhkcmF3VHgJAQ53aXRoZHJhd1Jlc3VsdAADCQAAAgUKd2l0aGRyYXdUeAUKd2l0aGRyYXdUeAkAzggCCQEMc3VwcGx5UmVzdWx0AQUGcG9vbElkCQEMcmVjYWxjUmVzdWx0AQAACQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAWkBBXN0YWtlAAQEdXNlcgkApQgBCAUBaQZjYWxsZXIEBmFtb3VudAgJAJEDAggFAWkIcGF5bWVudHMAAAZhbW91bnQEC2N1cnJlbnRQb29sCQEJdHJ5R2V0U3RyAgUEdGhpcwILY3VycmVudFBvb2wDAwkAZwIAAAUGYW1vdW50BgkBAiE9AggJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkCQDZBAEFB2Fzc2V0SWQJAAIBAhZpbnZhbGlkIHRva2VuIGF0dGFjaGVkAwkAAAIFC2N1cnJlbnRQb29sAgAJAAIBAhRQb29sIG5vdCBpbml0aWFsaXplZAkAzggCCQELc3Rha2VSZXN1bHQCBQR1c2VyBQZhbW91bnQJAQxzdXBwbHlSZXN1bHQBBQtjdXJyZW50UG9vbAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXkoB3hB", "height": 2340138, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: GJgHWHssEwXM3uEng789AxfCXnvBHtpa3oYkfh164TtW Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let Scale6 = 1000000 | |
5 | + | ||
6 | + | let Scale8 = 100000000 | |
7 | + | ||
8 | + | let Scale16 = (Scale8 * Scale8) | |
9 | + | ||
10 | + | let validators = [""] | |
11 | + | ||
12 | + | let assetId = "HHmaFQpUobwKxzjz4ECaBPtoF69kujKwU2cozaUzTsgv" | |
13 | + | ||
14 | + | let puzzlePools = ["3N6StJdgmTfARsRNn9Xt5rDYEs3pr4KGy1v"] | |
15 | + | ||
16 | + | func getBalance (assetId) = match assetId { | |
17 | + | case x: Unit => | |
18 | + | wavesBalance(this).available | |
19 | + | case _ => | |
20 | + | assetBalance(this, value(assetId)) | |
21 | + | } | |
22 | + | ||
23 | + | ||
24 | + | func tryGetInt (address,key) = match getInteger(address, key) { | |
25 | + | case b: Int => | |
26 | + | b | |
27 | + | case _ => | |
28 | + | 0 | |
29 | + | } | |
30 | + | ||
31 | + | ||
32 | + | func tryGetStr (address,key) = match getString(address, key) { | |
33 | + | case b: String => | |
34 | + | b | |
35 | + | case _ => | |
36 | + | "" | |
37 | + | } | |
38 | + | ||
39 | + | ||
40 | + | func getAssetString (assetId) = match assetId { | |
41 | + | case b: ByteVector => | |
42 | + | toBase58String(b) | |
43 | + | case _ => | |
44 | + | "WAVES" | |
45 | + | } | |
46 | + | ||
47 | + | ||
48 | + | func getPuzzlePoolSuppliedAmount (poolId) = { | |
49 | + | let balance = assetBalance(Address(fromBase58String(poolId)), fromBase58String(assetId)) | |
50 | + | balance | |
51 | + | } | |
52 | + | ||
53 | + | ||
54 | + | func getTotalSuppliedAmount () = { | |
55 | + | let currentPool = tryGetStr(this, "currentPool") | |
56 | + | if ((currentPool == "")) | |
57 | + | then throw(("Cannot find pool with id " + currentPool)) | |
58 | + | else getPuzzlePoolSuppliedAmount(currentPool) | |
59 | + | } | |
60 | + | ||
61 | + | ||
62 | + | func withdrawFromPuzzlePool (poolId,amount) = { | |
63 | + | let poolAddress = Address(fromBase58String(poolId)) | |
64 | + | let withdrawTx = if ((amount > 0)) | |
65 | + | then invoke(poolAddress, "withdraw", [assetId, amount], nil) | |
66 | + | else "" | |
67 | + | if ((withdrawTx == withdrawTx)) | |
68 | + | then withdrawTx | |
69 | + | else throw("Strict value is not equal to itself.") | |
70 | + | } | |
71 | + | ||
72 | + | ||
73 | + | func calculateSRate () = { | |
74 | + | let lastCheckSRate = tryGetInt(this, "global_lastCheckSRate") | |
75 | + | 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)) | |
79 | + | if ((stakedAmount == 0)) | |
80 | + | then Scale8 | |
81 | + | else { | |
82 | + | let sRate = (lastCheckSRate + fraction((blocks * Scale8), stakingEmission, stakedAmount)) | |
83 | + | if ((Scale8 > sRate)) | |
84 | + | then Scale8 | |
85 | + | else sRate | |
86 | + | } | |
87 | + | } | |
88 | + | ||
89 | + | ||
90 | + | func recalcResult (stakedChange) = { | |
91 | + | let stakedAmount = tryGetInt(this, "global_staked") | |
92 | + | let sRate = calculateSRate() | |
93 | + | [IntegerEntry("global_staked", (stakedAmount + stakedChange)), IntegerEntry("global_lastCheckSRate", sRate), IntegerEntry("global_lastCheckSRateHeight", height)] | |
94 | + | } | |
95 | + | ||
96 | + | ||
97 | + | func supplyResult (poolId) = if ((indexOf(puzzlePools, poolId) == unit)) | |
98 | + | then throw(("Unknown poolId " + poolId)) | |
99 | + | else { | |
100 | + | let assetBytes = fromBase58String(assetId) | |
101 | + | let balance = getBalance(assetBytes) | |
102 | + | let inv = invoke(Address(fromBase58String(poolId)), "supply", nil, [AttachedPayment(assetBytes, balance)]) | |
103 | + | if ((inv == inv)) | |
104 | + | then [StringEntry("currentPool", poolId)] | |
105 | + | else throw("Strict value is not equal to itself.") | |
106 | + | } | |
107 | + | ||
108 | + | ||
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 | + | func stakeResult (user,amount) = { | |
124 | + | let sAmount = fraction(amount, Scale8, calculateSRate()) | |
125 | + | (recalcResult(sAmount) ++ [IntegerEntry((user + "_staked"), (tryGetInt(this, (user + "_staked")) + sAmount))]) | |
126 | + | } | |
127 | + | ||
128 | + | ||
129 | + | @Callable(i) | |
130 | + | func rebalance (poolId) = { | |
131 | + | let currentPool = tryGetStr(this, "currentPool") | |
132 | + | if ((indexOf(validators, toString(i.caller)) == unit)) | |
133 | + | then throw("Access denied") | |
134 | + | else if ((currentPool == poolId)) | |
135 | + | then throw(("Already supplied to" + currentPool)) | |
136 | + | else { | |
137 | + | let withdrawTx = withdrawResult() | |
138 | + | if ((withdrawTx == withdrawTx)) | |
139 | + | then (supplyResult(poolId) ++ recalcResult(0)) | |
140 | + | else throw("Strict value is not equal to itself.") | |
141 | + | } | |
142 | + | } | |
143 | + | ||
144 | + | ||
145 | + | ||
146 | + | @Callable(i) | |
147 | + | func stake () = { | |
148 | + | let user = toString(i.caller) | |
149 | + | let amount = i.payments[0].amount | |
150 | + | let currentPool = tryGetStr(this, "currentPool") | |
151 | + | if (if ((0 >= amount)) | |
152 | + | then true | |
153 | + | else (i.payments[0].assetId != fromBase58String(assetId))) | |
154 | + | then throw("invalid token attached") | |
155 | + | else if ((currentPool == "")) | |
156 | + | then throw("Pool not initialized") | |
157 | + | else (stakeResult(user, amount) ++ supplyResult(currentPool)) | |
158 | + | } | |
159 | + | ||
160 | + | ||
161 | + | @Verifier(tx) | |
162 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
163 | + |
github/deemru/w8io/169f3d6 23.30 ms ◑