tx · iagmBQd5s4ACoPgKuu5dDpiEWRo7oDUQSJ43x9jpEQA 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq: -0.01300000 Waves 2023.07.26 17:30 [2682953] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves
{ "type": 13, "id": "iagmBQd5s4ACoPgKuu5dDpiEWRo7oDUQSJ43x9jpEQA", "fee": 1300000, "feeAssetId": null, "timestamp": 1690381792563, "version": 2, "chainId": 84, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "5GSX8sggvtxBGqmYWgnQsnssVgbV3rMd7EMurzCehxnf79q168Exn8wdv4xHEdc39xt1SqNcMufSnFd563zWPUFm" ], "script": "base64:BgIQCAISBQoDAQgIEgUKAwEICBgAA1NFUAICX18ACGZlZVNjYWxlCQC2AgEAgMLXLwEPZ2V0U3RyaW5nT3JGYWlsAQNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQR0aGlzBQNrZXkJAKwCAgIVTm8gZGF0YSBmb3IgdGhpcy5rZXk9BQNrZXkADHBvb2xEaXNhYmxlZAkAAgECDVBvb2wgZGlzYWJsZWQADHBvb2xOb3RFeGlzdAkAAgECEVBvb2wgaXMgbm90IGV4aXN0AA5zbGlwcGFnZVRvb0JpZwkAAgECE1NsaXBwYWdlIGlzIHRvbyBiaWcBE2tleU1hbmFnZXJQdWJsaWNLZXkAAhQlc19fbWFuYWdlclB1YmxpY0tleQEWa2V5TWFuYWdlclZhdWx0QWRkcmVzcwACFyVzX19tYW5hZ2VyVmF1bHRBZGRyZXNzAQJmYwACEyVzX19mYWN0b3J5Q29udHJhY3QAD2ZhY3RvcnlDb250cmFjdAkBEUBleHRyTmF0aXZlKDEwNjIpAQkBD2dldFN0cmluZ09yRmFpbAEJAQJmYwABC3Byb3RvY29s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XltZW50AgUWYXNzZXRJbkF0dGFjaGVkUGF5bWVudAkAoAMBBQ1jbGVhbkFtb3VudEluBQNuaWwDCQABAgUBQAIDSW50BQFACQACAQkArAICCQADAQUBQAIYIGNvdWxkbid0IGJlIGNhc3QgdG8gSW50CQCUCgIJAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwUTZmVlQ29sbGVjdG9yQWRkcmVzcwkAoAMBBRFmZWVQcm90b2NvbEFtb3VudAUWYXNzZXRJbkF0dGFjaGVkUGF5bWVudAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDBQdwb29sQWRyCQCgAwEFDWZlZVBvb2xBbW91bnQFFmFzc2V0SW5BdHRhY2hlZFBheW1lbnQFA25pbAULdG90YWxHZXRSYXcJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAnR4AQZ2ZXJpZnkABA90YXJnZXRQdWJsaWNLZXkEByRtYXRjaDAJARZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAJwawUHJG1hdGNoMAUCcGsDCQABAgUHJG1hdGNoMAIEVW5pdAgFAnR4D3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQ90YXJnZXRQdWJsaWNLZXnlJ/WP", "height": 2682953, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6E7AJAL9JMV4gZg7a6XTZ5rDXmhx3wGLr2XpbPSi7f7f Next: Aqa2PjQNBQtuAGrfk4HVzGNDgTSJhossQtug3jbYkwL1 Diff:
Old | New | Differences | |
---|---|---|---|
90 | 90 | else assetBalance(this, fromBase58String(assetId)) | |
91 | 91 | ||
92 | 92 | ||
93 | + | func getSwapFees (poolAddressStr) = { | |
94 | + | let poolFeeDefault = value(getInteger(this, poolFee())) | |
95 | + | let protocolFeeDefault = value(getInteger(this, protocolFee())) | |
96 | + | match invoke(factoryContract, "getSwapFeeREADONLY", [poolAddressStr], nil) { | |
97 | + | case fees: (Int, Int) => | |
98 | + | $Tuple2(fees._1, fees._2) | |
99 | + | case _ => | |
100 | + | $Tuple2(poolFeeDefault, protocolFeeDefault) | |
101 | + | } | |
102 | + | } | |
103 | + | ||
104 | + | ||
93 | 105 | func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = { | |
94 | 106 | let lpNonReverse = { | |
95 | 107 | let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
103 | 115 | then @ | |
104 | 116 | else unit | |
105 | 117 | } | |
106 | - | let $ | |
118 | + | let $t029983457 = if ((lpNonReverse != unit)) | |
107 | 119 | then { | |
108 | 120 | let pool = { | |
109 | 121 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil) | |
124 | 136 | $Tuple2(true, pool) | |
125 | 137 | } | |
126 | 138 | else poolNotExist | |
127 | - | let isReverse = $ | |
128 | - | let pool = $ | |
139 | + | let isReverse = $t029983457._1 | |
140 | + | let pool = $t029983457._2 | |
129 | 141 | let poolStatus = { | |
130 | 142 | let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil) | |
131 | 143 | if ($isInstanceOf(@, "Int")) | |
146 | 158 | ||
147 | 159 | @Callable(i) | |
148 | 160 | func swapCalculateREADONLY (amountIn,assetIn,assetOut) = { | |
149 | - | let prFee = value(getInteger(protocolFee())) | |
161 | + | let $t038533931 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
162 | + | let poolAdr = $t038533931._1 | |
163 | + | let isReverse = $t038533931._2 | |
164 | + | let $t039353987 = getSwapFees(toString(poolAdr)) | |
165 | + | let plFee = $t039353987._1 | |
166 | + | let prFee = $t039353987._2 | |
150 | 167 | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
151 | - | let plFee = value(getInteger(poolFee())) | |
152 | 168 | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
153 | 169 | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
154 | 170 | then toBigInt(1) | |
157 | 173 | then toBigInt(1) | |
158 | 174 | else feePoolAmountCalc | |
159 | 175 | let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
160 | - | let $t040634141 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
161 | - | let poolAdr = $t040634141._1 | |
162 | - | let isReverse = $t040634141._2 | |
163 | 176 | let res = { | |
164 | 177 | let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil) | |
165 | 178 | if ($isInstanceOf(@, "Int")) | |
181 | 194 | then "WAVES" | |
182 | 195 | else toBase58String(value(pmt.assetId)) | |
183 | 196 | let amountIn = value(pmt.amount) | |
184 | - | let prFee = value(getInteger(protocolFee())) | |
197 | + | let $t050005078 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
198 | + | let poolAdr = $t050005078._1 | |
199 | + | let isReverse = $t050005078._2 | |
200 | + | let $t050815133 = getSwapFees(toString(poolAdr)) | |
201 | + | let plFee = $t050815133._1 | |
202 | + | let prFee = $t050815133._2 | |
185 | 203 | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
186 | - | let plFee = value(getInteger(poolFee())) | |
187 | 204 | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
188 | 205 | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
189 | 206 | then toBigInt(1) | |
197 | 214 | else throw("exactly 1 payment are expected")] | |
198 | 215 | if ((checks == checks)) | |
199 | 216 | then { | |
200 | - | let $t053435421 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
201 | - | let poolAdr = $t053435421._1 | |
202 | - | let isReverse = $t053435421._2 | |
203 | 217 | let assetInAttachedPayment = if ((assetIn == "WAVES")) | |
204 | 218 | then unit | |
205 | 219 | else fromBase58String(assetIn) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let feeScale = toBigInt(100000000) | |
7 | 7 | ||
8 | 8 | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key)) | |
9 | 9 | ||
10 | 10 | ||
11 | 11 | let poolDisabled = throw("Pool disabled") | |
12 | 12 | ||
13 | 13 | let poolNotExist = throw("Pool is not exist") | |
14 | 14 | ||
15 | 15 | let slippageTooBig = throw("Slippage is too big") | |
16 | 16 | ||
17 | 17 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func keyManagerVaultAddress () = "%s__managerVaultAddress" | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func fc () = "%s__factoryContract" | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | let factoryContract = addressFromStringValue(getStringOrFail(fc())) | |
27 | 27 | ||
28 | 28 | func protocolFee () = makeString(["%s", "protocolFee"], SEP) | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func poolFee () = makeString(["%s", "poolFee"], SEP) | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getStringOrFailFromAddress (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | let keyFeeCollectorAddress = "%s__feeCollectorAddress" | |
38 | 38 | ||
39 | 39 | let feeCollectorAddress = addressFromStringValue(getStringOrFailFromAddress(factoryContract, keyFeeCollectorAddress)) | |
40 | 40 | ||
41 | 41 | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { | |
42 | 42 | case s: String => | |
43 | 43 | addressFromStringValue(s) | |
44 | 44 | case _ => | |
45 | 45 | this | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func asInt (val) = match val { | |
50 | 50 | case valInt: Int => | |
51 | 51 | valInt | |
52 | 52 | case _ => | |
53 | 53 | throw("fail to cast into Int") | |
54 | 54 | } | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP) | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func managerPublicKeyOrUnit () = { | |
61 | 61 | let managerVaultAddress = getManagerVaultAddressOrThis() | |
62 | 62 | match getString(managerVaultAddress, keyManagerPublicKey()) { | |
63 | 63 | case s: String => | |
64 | 64 | fromBase58String(s) | |
65 | 65 | case _: Unit => | |
66 | 66 | unit | |
67 | 67 | case _ => | |
68 | 68 | throw("Match error") | |
69 | 69 | } | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | func isManager (i) = match managerPublicKeyOrUnit() { | |
74 | 74 | case pk: ByteVector => | |
75 | 75 | (i.callerPublicKey == pk) | |
76 | 76 | case _: Unit => | |
77 | 77 | (i.caller == this) | |
78 | 78 | case _ => | |
79 | 79 | throw("Match error") | |
80 | 80 | } | |
81 | 81 | ||
82 | 82 | ||
83 | 83 | func mustManager (i) = if (isManager(i)) | |
84 | 84 | then true | |
85 | 85 | else throw("permission denied") | |
86 | 86 | ||
87 | 87 | ||
88 | 88 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
89 | 89 | then wavesBalance(this).available | |
90 | 90 | else assetBalance(this, fromBase58String(assetId)) | |
91 | 91 | ||
92 | 92 | ||
93 | + | func getSwapFees (poolAddressStr) = { | |
94 | + | let poolFeeDefault = value(getInteger(this, poolFee())) | |
95 | + | let protocolFeeDefault = value(getInteger(this, protocolFee())) | |
96 | + | match invoke(factoryContract, "getSwapFeeREADONLY", [poolAddressStr], nil) { | |
97 | + | case fees: (Int, Int) => | |
98 | + | $Tuple2(fees._1, fees._2) | |
99 | + | case _ => | |
100 | + | $Tuple2(poolFeeDefault, protocolFeeDefault) | |
101 | + | } | |
102 | + | } | |
103 | + | ||
104 | + | ||
93 | 105 | func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = { | |
94 | 106 | let lpNonReverse = { | |
95 | 107 | let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
96 | 108 | if ($isInstanceOf(@, "String")) | |
97 | 109 | then @ | |
98 | 110 | else unit | |
99 | 111 | } | |
100 | 112 | let lpReverse = { | |
101 | 113 | let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
102 | 114 | if ($isInstanceOf(@, "String")) | |
103 | 115 | then @ | |
104 | 116 | else unit | |
105 | 117 | } | |
106 | - | let $ | |
118 | + | let $t029983457 = if ((lpNonReverse != unit)) | |
107 | 119 | then { | |
108 | 120 | let pool = { | |
109 | 121 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil) | |
110 | 122 | if ($isInstanceOf(@, "String")) | |
111 | 123 | then @ | |
112 | 124 | else throw(($getType(@) + " couldn't be cast to String")) | |
113 | 125 | } | |
114 | 126 | $Tuple2(false, pool) | |
115 | 127 | } | |
116 | 128 | else if ((lpReverse != unit)) | |
117 | 129 | then { | |
118 | 130 | let pool = { | |
119 | 131 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil) | |
120 | 132 | if ($isInstanceOf(@, "String")) | |
121 | 133 | then @ | |
122 | 134 | else throw(($getType(@) + " couldn't be cast to String")) | |
123 | 135 | } | |
124 | 136 | $Tuple2(true, pool) | |
125 | 137 | } | |
126 | 138 | else poolNotExist | |
127 | - | let isReverse = $ | |
128 | - | let pool = $ | |
139 | + | let isReverse = $t029983457._1 | |
140 | + | let pool = $t029983457._2 | |
129 | 141 | let poolStatus = { | |
130 | 142 | let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil) | |
131 | 143 | if ($isInstanceOf(@, "Int")) | |
132 | 144 | then @ | |
133 | 145 | else throw(($getType(@) + " couldn't be cast to Int")) | |
134 | 146 | } | |
135 | 147 | let check = if ((poolStatus == 1)) | |
136 | 148 | then true | |
137 | 149 | else poolDisabled | |
138 | 150 | if ((check == check)) | |
139 | 151 | then { | |
140 | 152 | let poolAdr = addressFromStringValue(valueOrElse(pool, "")) | |
141 | 153 | $Tuple2(poolAdr, isReverse) | |
142 | 154 | } | |
143 | 155 | else throw("Strict value is not equal to itself.") | |
144 | 156 | } | |
145 | 157 | ||
146 | 158 | ||
147 | 159 | @Callable(i) | |
148 | 160 | func swapCalculateREADONLY (amountIn,assetIn,assetOut) = { | |
149 | - | let prFee = value(getInteger(protocolFee())) | |
161 | + | let $t038533931 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
162 | + | let poolAdr = $t038533931._1 | |
163 | + | let isReverse = $t038533931._2 | |
164 | + | let $t039353987 = getSwapFees(toString(poolAdr)) | |
165 | + | let plFee = $t039353987._1 | |
166 | + | let prFee = $t039353987._2 | |
150 | 167 | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
151 | - | let plFee = value(getInteger(poolFee())) | |
152 | 168 | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
153 | 169 | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
154 | 170 | then toBigInt(1) | |
155 | 171 | else feeProtocolAmountCalc | |
156 | 172 | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
157 | 173 | then toBigInt(1) | |
158 | 174 | else feePoolAmountCalc | |
159 | 175 | let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
160 | - | let $t040634141 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
161 | - | let poolAdr = $t040634141._1 | |
162 | - | let isReverse = $t040634141._2 | |
163 | 176 | let res = { | |
164 | 177 | let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil) | |
165 | 178 | if ($isInstanceOf(@, "Int")) | |
166 | 179 | then @ | |
167 | 180 | else throw(($getType(@) + " couldn't be cast to Int")) | |
168 | 181 | } | |
169 | 182 | $Tuple2(nil, res) | |
170 | 183 | } | |
171 | 184 | ||
172 | 185 | ||
173 | 186 | ||
174 | 187 | @Callable(i) | |
175 | 188 | func swap (amountOutMin,assetOutRaw,addressTo) = { | |
176 | 189 | let assetOut = if ((assetOutRaw == "")) | |
177 | 190 | then "WAVES" | |
178 | 191 | else assetOutRaw | |
179 | 192 | let pmt = value(i.payments[0]) | |
180 | 193 | let assetIn = if ((pmt.assetId == unit)) | |
181 | 194 | then "WAVES" | |
182 | 195 | else toBase58String(value(pmt.assetId)) | |
183 | 196 | let amountIn = value(pmt.amount) | |
184 | - | let prFee = value(getInteger(protocolFee())) | |
197 | + | let $t050005078 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
198 | + | let poolAdr = $t050005078._1 | |
199 | + | let isReverse = $t050005078._2 | |
200 | + | let $t050815133 = getSwapFees(toString(poolAdr)) | |
201 | + | let plFee = $t050815133._1 | |
202 | + | let prFee = $t050815133._2 | |
185 | 203 | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
186 | - | let plFee = value(getInteger(poolFee())) | |
187 | 204 | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
188 | 205 | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
189 | 206 | then toBigInt(1) | |
190 | 207 | else feeProtocolAmountCalc | |
191 | 208 | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
192 | 209 | then toBigInt(1) | |
193 | 210 | else feePoolAmountCalc | |
194 | 211 | let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
195 | 212 | let checks = [if ((size(i.payments) == 1)) | |
196 | 213 | then true | |
197 | 214 | else throw("exactly 1 payment are expected")] | |
198 | 215 | if ((checks == checks)) | |
199 | 216 | then { | |
200 | - | let $t053435421 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
201 | - | let poolAdr = $t053435421._1 | |
202 | - | let isReverse = $t053435421._2 | |
203 | 217 | let assetInAttachedPayment = if ((assetIn == "WAVES")) | |
204 | 218 | then unit | |
205 | 219 | else fromBase58String(assetIn) | |
206 | 220 | let totalGetRaw = { | |
207 | 221 | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo, toInt(feePoolAmount)], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))]) | |
208 | 222 | if ($isInstanceOf(@, "Int")) | |
209 | 223 | then @ | |
210 | 224 | else throw(($getType(@) + " couldn't be cast to Int")) | |
211 | 225 | } | |
212 | 226 | $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw) | |
213 | 227 | } | |
214 | 228 | else throw("Strict value is not equal to itself.") | |
215 | 229 | } | |
216 | 230 | ||
217 | 231 | ||
218 | 232 | @Verifier(tx) | |
219 | 233 | func verify () = { | |
220 | 234 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
221 | 235 | case pk: ByteVector => | |
222 | 236 | pk | |
223 | 237 | case _: Unit => | |
224 | 238 | tx.senderPublicKey | |
225 | 239 | case _ => | |
226 | 240 | throw("Match error") | |
227 | 241 | } | |
228 | 242 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
229 | 243 | } | |
230 | 244 |
github/deemru/w8io/169f3d6 37.82 ms ◑