-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofileChecker.html
528 lines (493 loc) · 18.3 KB
/
profileChecker.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Circles Checker (v1 & v2)</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
<style>
body {
margin: 0;
font-family: 'Inter', Helvetica, Arial, sans-serif;
background: #ffffff;
color: #333;
line-height: 1.3;
}
header {
background: #5C49E4;
color: #fff;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
font-weight: 600;
font-size: 1.5rem;
}
p {
margin: 0.5rem 0 0;
font-weight: 400;
}
/* Reduced left margin for a more left-aligned layout */
.container {
max-width: 800px;
margin: 40px 0 40px 10px;
padding: 0 20px;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
}
input {
padding: 10px;
width: 100%;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
margin-top: 10px;
padding: 10px 20px;
background: #5C49E4;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
font-weight: 600;
}
button:hover {
background: #4A39CC;
}
#result {
margin-top: 20px;
padding: 20px;
border-radius: 8px;
background: #fafafa;
border: 1px solid #eee;
min-height: 200px;
}
.info {
margin: 0.3rem 0;
line-height: 1.3;
}
.address-link {
color: #5C49E4;
text-decoration: none;
font-weight: 500;
cursor: pointer;
}
.address-link:hover {
text-decoration: underline;
}
table {
border-collapse: collapse;
margin-top: 10px;
width: 100%;
font-size: 0.95rem;
background: #fff;
border-radius: 6px;
overflow: hidden;
border: 1px solid #eee;
}
th, td {
text-align: left;
padding: 10px;
white-space: nowrap;
}
th {
background: #f9f9fc;
font-weight: 600;
border-bottom: 1px solid #eee;
}
tr:nth-child(even) {
background: #fafafa;
}
tr:hover td {
background: #f3f3f7;
}
td {
border-bottom: 1px solid #eee;
}
strong {
font-weight: 600;
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #5C49E4;
border-radius: 50%;
width: 24px;
height: 24px;
animation: spin 1s linear infinite;
display: inline-block;
vertical-align: middle;
margin-left: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<header>
<h1>Circles Checker (v1 & v2)</h1>
<p>Check an address to see Circles v1 & v2 status and trusted addresses.</p>
</header>
<div class="container">
<label for="addressInput">Address:</label>
<input type="text" id="addressInput" value="0x42cEDde51198D1773590311E2A340DC06B24cB37" />
<button id="checkButton">Check Address</button>
<div id="result"></div>
</div>
<!-- Ethers.js UMD build -->
<script src="https://cdn.jsdelivr.net/npm/ethers@5.7.2/dist/ethers.umd.min.js"></script>
<script>
/********************************************************
* Contract ABIs and addresses
********************************************************/
// 1) Helper contract to get the Circles v1 & v2 data
const helperABI = [
"function getAllDataForUser(address user) external view returns (tuple(bool isOrg, bool isHuman, uint256 totalSupply, bool stopped, uint256 lastTouched) v1Data, tuple(bool isHuman, bool isOrg, bool isGroup, uint256 crcAmount, uint256 ts1, uint256 ts2, uint256 totalSupply) v2Data, tuple(address trustedAddress, uint256 expiry, bool v1Org, bool v1Human, bool v2Human, bool v2Org, bool v2Group, uint256 v2TotalSupply, uint256 userHolds)[] trustedAddresses)"
];
const helperAddress = "0xD5934724C19f9DbEeBC263066D627872e55e63Aa";
// 2) Contract for "getAvatarsERC20(address[] calldata avatars)"
const avatarERC20ABI = [
"function getAvatarsERC20(address[] calldata avatars) external view returns (tuple(address staticERC20, address demurragedERC20)[] memory tokens)"
];
const avatarERC20Address = "0xeBe64dd348d1204391f6617f632cF99Af0b75561";
// Ethers.js provider (Gnosis chain)
const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/gnosis");
// Contract instances
const helperContract = new ethers.Contract(helperAddress, helperABI, provider);
const avatarERC20Contract = new ethers.Contract(avatarERC20Address, avatarERC20ABI, provider);
// Elements
const checkButton = document.getElementById("checkButton");
const resultDiv = document.getElementById("result");
const addressInput = document.getElementById("addressInput");
/********************************************************
* Profile name lookup
********************************************************/
async function getProfileName(address) {
try {
const queryAddress = address.toLowerCase();
const url = `https://rpc.aboutcircles.com/profiles/search?address=${queryAddress}`;
const response = await fetch(url);
if (!response.ok) {
return "No name";
}
const data = await response.json();
if (Array.isArray(data)) {
const profile = data.find(entry =>
entry.address.toLowerCase() === queryAddress
);
return profile?.name || "No name";
}
return "No name";
} catch (error) {
console.error("Error fetching profile for", address, error);
return "No name";
}
}
/********************************************************
* Balancer price lookup (using returnAmount as Price)
********************************************************/
async function getPrice(erc20Address) {
if (!erc20Address || erc20Address === ethers.constants.AddressZero) {
return "N/A";
}
try {
const query = `
{
sorGetSwapPaths(
chain: GNOSIS,
swapAmount: "0.1",
swapType: EXACT_IN,
tokenIn: "${erc20Address}",
tokenOut: "0xaf204776c7245bf4147c2612bf6e5972ee483701"
) {
returnAmount
effectivePrice
protocolVersion
effectivePriceReversed
priceImpact {
priceImpact
error
}
}
}
`;
const response = await fetch("https://api-v3.balancer.fi/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query })
});
const data = await response.json();
if (
data.data &&
data.data.sorGetSwapPaths &&
data.data.sorGetSwapPaths.returnAmount
) {
return data.data.sorGetSwapPaths.returnAmount * 10;
}
return "N/A";
} catch (err) {
console.error("Error fetching price for", erc20Address, err);
return "N/A";
}
}
/********************************************************
* Pool lookup for a token via Balancer's GraphQL API
********************************************************/
async function getPoolsForToken(tokenAddress) {
try {
const query = `
{
poolGetPools(where: {tokensIn: ["${tokenAddress}"]}) {
id
address
name
}
}
`;
const response = await fetch("https://api-v3.balancer.fi/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query })
});
const data = await response.json();
if (data.data && data.data.poolGetPools) {
return data.data.poolGetPools;
}
return [];
} catch (err) {
console.error("Error fetching pools for token", tokenAddress, err);
return [];
}
}
/********************************************************
* Utility functions
********************************************************/
function relativeTimeSince(timestamp) {
const now = Date.now();
const diffMs = now - (timestamp * 1000);
if (diffMs < 0) return "in the future";
const diffMinutes = Math.floor(diffMs / 60000);
const minutes = diffMinutes % 60;
const hours = Math.floor(diffMinutes / 60);
let result = "";
if (hours > 0) {
result += hours + "h ";
}
result += minutes + "m ago";
return result.trim();
}
function formatExpiry(expiry) {
const indefiniteVal = ethers.BigNumber.from("79228162514264337593543950335");
if (ethers.BigNumber.from(expiry).eq(indefiniteVal)) {
return "indefinite";
}
const expiryNum = Number(expiry);
const date = new Date(expiryNum * 1000);
if (isNaN(date.getTime())) return "Invalid Date";
return date.toUTCString();
}
/********************************************************
* Main check function
********************************************************/
async function checkAddress(inputAddress) {
// Update URL to include current address.
window.history.replaceState(null, "", "?address=" + inputAddress);
resultDiv.innerHTML = "";
if (!ethers.utils.isAddress(inputAddress)) {
resultDiv.innerHTML = "<p style='color:red;'>Invalid address</p>";
return;
}
// Show loader.
const loader = document.createElement("div");
loader.className = "loader";
const loadingText = document.createElement("span");
loadingText.textContent = "Fetching data...";
resultDiv.appendChild(loadingText);
resultDiv.appendChild(loader);
try {
// 1) Get on-chain data for main user.
const data = await helperContract.getAllDataForUser(inputAddress);
const v1Data = data.v1Data;
const v2Data = data.v2Data;
const trustedAddresses = data.trustedAddresses;
// 2) Build list of addresses (main + trusted).
const addressList = [inputAddress];
for (let i = 0; i < trustedAddresses.length; i++) {
addressList.push(trustedAddresses[i].trustedAddress);
}
// 3) Single call to getAvatarsERC20.
const erc20Array = await avatarERC20Contract.getAvatarsERC20(addressList);
// 4) Build map: address -> { staticERC20, demurragedERC20 }.
const erc20Map = {};
addressList.forEach((addr, idx) => {
erc20Map[addr.toLowerCase()] = {
staticERC20: erc20Array[idx].staticERC20,
demurragedERC20: erc20Array[idx].demurragedERC20
};
});
// 5) Remove loader.
resultDiv.innerHTML = "";
// ----- MAIN USER DISPLAY -----
const mainDisplayName = await getProfileName(inputAddress);
const mainERC20Data = erc20Map[inputAddress.toLowerCase()] || { staticERC20: "", demurragedERC20: "" };
const mainDemurraged = mainERC20Data.demurragedERC20;
const mainPrice = await getPrice(mainDemurraged);
let html = `<div class="info"><strong>Address:</strong> ${mainDisplayName}</div>`;
html += `<div class="info"><strong>Price:</strong> ${mainPrice}</div>`;
// V1 Info.
html += `<div class="info"><strong>[V1] Status:</strong> ${v1Data.isHuman ? 'human' : (v1Data.isOrg ? 'org' : 'none')}</div>`;
if (v1Data.isHuman) {
html += `<div class="info"><strong>[V1] Total Supply:</strong> ${ethers.utils.formatUnits(v1Data.totalSupply, 18)}</div>`;
html += `<div class="info"><strong>[V1] Stopped:</strong> ${v1Data.stopped}</div>`;
const lastMintV1 = v1Data.lastTouched == 0 ? "N/A" : new Date(v1Data.lastTouched * 1000).toLocaleString();
html += `<div class="info"><strong>[V1] Last Mint:</strong> ${lastMintV1}</div>`;
}
// V2 Info.
html += `<div class="info"><strong>[V2] Status:</strong> ${v2Data.isHuman ? 'human' : (v2Data.isOrg ? 'org' : (v2Data.isGroup ? 'group' : 'none'))}</div>`;
if (v2Data.isHuman || v2Data.isGroup) {
html += `<div class="info"><strong>[V2] CRC Amount:</strong> ${ethers.utils.formatUnits(v2Data.crcAmount, 18)}</div>`;
const lastMintV2 = v2Data.ts1 == 0 ? "N/A" : relativeTimeSince(v2Data.ts1);
html += `<div class="info"><strong>[V2] Last Mint:</strong> ${lastMintV2}</div>`;
html += `<div class="info"><strong>[V2] Total Supply:</strong> ${ethers.utils.formatUnits(v2Data.totalSupply, 18)}</div>`;
}
// Add ERC20 (demurraged) for main user.
html += `<div class="info"><strong>ERC20 (demurraged):</strong> ${mainDemurraged}</div>`;
// ----- TRUSTED ADDRESSES TABLE -----
if (trustedAddresses.length > 0) {
html += `<div class="info"><strong>[V2] Trusted Addresses:</strong></div>`;
html += `
<table>
<thead>
<tr>
<th>Trusted Address</th>
<th>Name</th>
<th>Price</th>
<th>Expiry</th>
<th>V1 State</th>
<th>V2 State</th>
<th>V2 Total Supply</th>
<th>User Holds</th>
<th>ERC20 (demurraged)</th>
</tr>
</thead>
<tbody>
`;
for (let i = 0; i < trustedAddresses.length; i++) {
const addrData = trustedAddresses[i];
let expiryValue;
if (i < trustedAddresses.length - 1) {
expiryValue = trustedAddresses[i + 1].expiry;
} else {
expiryValue = null;
}
const expiryDisplay = expiryValue ? formatExpiry(expiryValue) : "N/A";
const v1State = addrData.v1Human ? 'human' : (addrData.v1Org ? 'org' : 'none');
const v2State = addrData.v2Human ? 'human' : (addrData.v2Org ? 'org' : (addrData.v2Group ? 'group' : 'none'));
const v2TotalSupply = addrData.v2TotalSupply !== 0 ? ethers.utils.formatUnits(addrData.v2TotalSupply, 18) : '-';
const userHolds = ethers.utils.formatUnits(addrData.userHolds, 18);
const trustedAddr = addrData.trustedAddress;
const demurragedERC20 = erc20Map[trustedAddr.toLowerCase()]?.demurragedERC20 || "N/A";
html += `
<tr>
<td>
<span class="address-link" data-address="${trustedAddr}">
${trustedAddr}
</span>
</td>
<td>
<span class="address-name" data-address="${trustedAddr}">
Loading...
</span>
</td>
<td>
<span class="price" data-address="${trustedAddr}">
Loading...
</span>
</td>
<td>${expiryDisplay}</td>
<td>${v1State}</td>
<td>${v2State}</td>
<td>${v2TotalSupply}</td>
<td>${userHolds}</td>
<td>
<span class="erc20" data-token="${demurragedERC20}">
${demurragedERC20}
</span>
</td>
</tr>
`;
}
html += `</tbody></table>`;
} else {
html += `<div class="info">[V2] No trusted addresses found.</div>`;
}
resultDiv.innerHTML = html;
// ---- Update trusted addresses: names and prices ----
const nameCells = document.querySelectorAll(".address-name");
const priceCells = document.querySelectorAll(".price");
for (const cell of nameCells) {
const addr = cell.getAttribute("data-address");
const profileName = await getProfileName(addr);
cell.textContent = profileName;
}
for (const cell of priceCells) {
const addr = cell.getAttribute("data-address");
const demurraged = erc20Map[addr.toLowerCase()]?.demurragedERC20;
if (!demurraged || demurraged === ethers.constants.AddressZero) {
cell.textContent = "N/A";
} else {
const retAmount = await getPrice(demurraged);
cell.textContent = retAmount;
}
}
// ---- Update ERC20 cells in the table to include pool links ----
const erc20Cells = document.querySelectorAll("span.erc20");
for (const cell of erc20Cells) {
const token = cell.textContent.trim();
// Skip if not a valid token address.
if (token === "N/A" || !ethers.utils.isAddress(token)) continue;
const pools = await getPoolsForToken(token);
if (pools.length > 0) {
// Build one or more links (comma-separated)
let links = pools.map(pool => `<a href="https://balancer.fi/pools/gnosis/v2/${pool.id}" target="_blank">${pool.name || pool.address}</a>`).join(", ");
cell.innerHTML = `${token}<br/><small>Pools: ${links}</small>`;
}
}
} catch (error) {
console.error(error);
resultDiv.innerHTML = `<p style='color:red;'>Error: ${error.message}</p>`;
}
}
/********************************************************
* Event listeners
********************************************************/
checkButton.addEventListener("click", async () => {
const addr = addressInput.value.trim();
await checkAddress(addr);
});
resultDiv.addEventListener("click", async (e) => {
if (e.target.classList.contains("address-link")) {
const addr = e.target.getAttribute("data-address");
addressInput.value = addr;
await checkAddress(addr);
}
});
window.addEventListener("load", async () => {
const urlParams = new URLSearchParams(window.location.search);
const addr = urlParams.get("address");
if (addr && ethers.utils.isAddress(addr)) {
addressInput.value = addr;
await checkAddress(addr);
}
});
</script>
</body>
</html>