-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgroupChecker.html
More file actions
1110 lines (1050 loc) · 54.6 KB
/
groupChecker.html
File metadata and controls
1110 lines (1050 loc) · 54.6 KB
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Group Checker</title>
<link
href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<style>
body {
margin: 0;
font-family: "DM Sans", sans-serif;
background: #fff7f5;
color: #191568;
line-height: 1.3;
}
header {
background: #191568;
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;
}
.container {
max-width: 900px;
margin: 40px 0 40px 0;
padding: 0 20px;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
}
input {
padding: 10px;
width: 100%;
max-width: 600px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button, .icon-btn {
margin-top: 0;
padding: 6px;
background: #ffede8;
color: #191568;
border: none;
border-radius: 50%;
cursor: pointer;
font-size: 1.1rem;
display: inline-flex;
align-items: center;
justify-content: center;
transition: background 0.2s;
width: 32px;
height: 32px;
margin-left: 2px;
margin-right: 0;
}
button:hover, .icon-btn:hover {
background: #ffe3dc;
}
.icon-btn[title] {
position: relative;
}
.icon-btn[title]:hover:after {
content: attr(title);
position: absolute;
left: 50%;
top: 110%;
transform: translateX(-50%);
background: #222;
color: #fff;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85rem;
white-space: nowrap;
z-index: 10;
}
#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: #191568;
text-decoration: none;
font-weight: 500;
cursor: pointer;
}
.address-link:hover {
text-decoration: underline;
}
table {
border-collapse: separate;
border-spacing: 0 8px;
margin-top: 10px;
width: 100%;
font-size: 0.97rem;
background: #fff;
border-radius: 8px;
overflow: hidden;
border: 1px solid #eee;
box-shadow: 0 2px 12px 0 rgba(25,21,104,0.07);
}
th,
td {
text-align: left;
padding: 12px 10px;
white-space: nowrap;
vertical-align: middle;
}
th {
background: #e5e3fb;
font-weight: 600;
border-bottom: 1px solid #eee;
}
tr {
background: #fff;
border-radius: 8px;
}
tr:nth-child(even) {
background: #fff7f5;
}
tr:hover td {
background: #ffede8;
}
td {
border-bottom: 1px solid #eee;
}
.address-container {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 100%;
}
.address-main {
font-weight: 400;
font-size: 0.98em;
color: #191568;
margin-bottom: 2px;
display: flex;
align-items: center;
gap: 6px;
width: 100%;
}
.profile-name {
font-weight: 600;
color: #222;
font-size: 1em;
margin-bottom: 2px;
}
.address-hex { display: none; }
ul {
margin: 0;
padding-left: 18px;
}
th.sortable {
cursor: pointer;
user-select: none;
position: relative;
padding-right: 20px;
}
th.sortable:hover {
background: #d5d3f5;
}
th.sortable::after {
content: '⇅';
position: absolute;
right: 4px;
opacity: 0.4;
font-size: 0.85em;
}
th.sortable.sort-desc::after {
content: '▼';
opacity: 0.8;
}
th.sortable.sort-asc::after {
content: '▲';
opacity: 0.8;
}
.unit-label {
cursor: pointer;
text-decoration: underline;
text-decoration-style: dotted;
margin-left: 1px;
}
.unit-label:hover {
color: #5c49e4;
}
.mint-btn {
background: #f4f4ff;
color: #191568;
border: none;
border-radius: 50%;
cursor: pointer;
font-size: 1.1rem;
width: 32px;
height: 32px;
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: 2px;
margin-right: 2px;
transition: background 0.2s;
}
.mint-btn:hover {
background: #e0e0fa;
}
</style>
</head>
<body>
<header>
<h1>Group Checker</h1>
<p>
Enter one or more group addresses (comma separated) to see group
details and associated ERC20 token data.
</p>
</header>
<div class="container">
<label for="groupInput">Group Addresses:</label>
<!-- Prepopulated with your specified group addresses -->
<input type="text" id="groupInput" value="" />
<button id="checkButton">Check Groups</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>
/*********************
* Profile Lookup Functionality
*********************/
async function getProfileName(address) {
try {
console.log("Fetching profile for address:", address);
const queryAddress = address.toLowerCase();
// Circles RPC
const url = `https://rpc.aboutcircles.com/profiles/search?address=${queryAddress}`;
// RINGS RPC
// const url = `https://static.94.138.251.148.clients.your-server.de/profiles/search?address=${queryAddress}`;
console.log("Request URL:", url);
const response = await fetch(url);
if (!response.ok) {
console.error(
"HTTP error",
response.status,
response.statusText,
);
return "No name";
}
const data = await response.json();
console.log("Profile response for", address, data);
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";
}
}
/*
Logic to find the whitelisted orgs upon initalisation
*/
async function fetchTrustedGroups(trusterAddress) {
const rpcEndpoint = "https://rpc.aboutcircles.com/";
const requestBody = {
jsonrpc: "2.0",
id: 1,
method: "circles_query",
params: [
{
Namespace: "V_CrcV2",
Table: "TrustRelations",
Columns: [],
Filter: [
{
Type: "FilterPredicate",
FilterType: "Equals",
Column: "truster",
Value: trusterAddress,
},
],
},
],
};
try {
const response = await fetch(rpcEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
});
if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status}`,
);
}
const data = await response.json();
if (data.error) {
throw new Error(`RPC error: ${data.error.message}`);
}
// Extract unique trustee addresses from the rows (trustee is at index 5)
const addresses = new Set(
data.result.rows.map((row) => row[5]),
);
return Array.from(addresses);
} catch (error) {
console.error("Error fetching trusted groups:", error);
return [];
}
}
/*********************
* Group Checker Logic
*********************/
// GroupInfoGetter contract address
const contractAddress = '0x3cd1c2be7ce9fc45b4c9a97ac9ef534fa85fc19d';
const abi = [
{
"inputs": [
{
"internalType": "address[]",
"name": "groupAddresses",
"type": "address[]"
}
],
"name": "getGroupsInfo",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "service",
"type": "address"
},
{
"internalType": "address",
"name": "feeCollection",
"type": "address"
},
{
"internalType": "address[]",
"name": "membershipConditions",
"type": "address[]"
},
{
"internalType": "address",
"name": "baseMintHandler",
"type": "address"
},
{
"internalType": "address",
"name": "baseMintPolicy",
"type": "address"
},
{
"internalType": "address",
"name": "baseTreasury",
"type": "address"
},
{
"internalType": "address",
"name": "hub",
"type": "address"
},
{
"internalType": "address",
"name": "staticERC20",
"type": "address"
},
{
"internalType": "address",
"name": "demurragedERC20",
"type": "address"
},
{
"internalType": "address",
"name": "nameRegistry",
"type": "address"
},
{
"internalType": "uint256",
"name": "maxConditions",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "erc1155TotalSupply",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "staticERC20TotalSupply",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "demurragedERC20TotalSupply",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"internalType": "struct GroupInfoGetter.GroupInfo[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
}
];
// Initialize ethers provider (Gnosis chain)
const provider = new ethers.providers.JsonRpcProvider(
"https://rpc.aboutcircles.com",
);
const groupGetterContract = new ethers.Contract(
contractAddress,
abi,
provider,
);
// CRC static/demurraged converter contract
const crcConverterContract = new ethers.Contract(
'0x0d8c4901Dd270Fe101B8014A5dbECC4e4432eB1E',
[
{ inputs: [{ internalType: "uint256", name: "_timestamp", type: "uint256" }], name: "day", outputs: [{ internalType: "uint64", name: "", type: "uint64" }], stateMutability: "view", type: "function" },
{ inputs: [{ internalType: "uint256", name: "_inflationaryValue", type: "uint256" }, { internalType: "uint64", name: "_day", type: "uint64" }], name: "convertInflationaryToDemurrageValue", outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "pure", type: "function" }
],
provider,
);
let staticToDemurragedFactor = 1;
let showDemurraged = true;
(async () => {
try {
const day = await crcConverterContract.day(Math.floor(Date.now() / 1000));
const result = await crcConverterContract.convertInflationaryToDemurrageValue(ethers.utils.parseEther('1'), day);
staticToDemurragedFactor = parseFloat(ethers.utils.formatEther(result));
console.log('Static→Demurraged factor:', staticToDemurragedFactor);
} catch (err) {
console.error('Failed to fetch conversion factor:', err);
}
})();
const checkButton = document.getElementById("checkButton");
const resultDiv = document.getElementById("result");
const groupInput = document.getElementById("groupInput");
async function checkGroups(input) {
// Clear previous results
resultDiv.innerHTML = "";
// Parse addresses (split by comma) and trim spaces
const addresses = input
.split(",")
.map((addr) => addr.trim())
.filter((addr) => addr !== "");
// Validate each address
for (let addr of addresses) {
if (!ethers.utils.isAddress(addr)) {
resultDiv.innerHTML = `<p style='color:red;'>Invalid address detected: ${addr}</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 {
// Call the getter function on-chain
const groups = await groupGetterContract.getGroupsInfo(addresses);
// Remove loader
resultDiv.innerHTML = "";
// Create the table
const table = document.createElement("table");
table.style.width = "100%";
table.style.marginBottom = "20px";
// Create table header
const thead = document.createElement("thead");
const headerRow = document.createElement("tr");
const headers = [
'Group Address', 'Owner', 'Total Supply',
'Static ERC20', 'Price/', 'sERC20 Supply ', 'Market Cap',
'Demurraged ERC20', 'Demurraged ERC20 Supply',
'Membership Conditions', 'Service', 'Base Mint Handler', 'Base Mint Policy', 'Base Treasury', 'Fee Collection'
];
const unitToggleLabels = [];
function toggleUnit(e) {
if (e) e.stopPropagation();
showDemurraged = !showDemurraged;
const unitText = showDemurraged ? 'CRC' : 's-CRC';
unitToggleLabels.forEach(s => { s.textContent = unitText; });
updateAllRows();
}
const sortableColumns = { 2: 'sortErc1155Supply', 4: 'sortPrice', 5: 'sortSupply', 6: 'sortMarketCap', 8: 'sortDemurragedSupply' };
let currentSort = { col: null, dir: null };
function sortTable(tbody, sortKey, dir) {
const rows = Array.from(tbody.querySelectorAll('tr'));
rows.sort((a, b) => {
const va = a[sortKey] || 0;
const vb = b[sortKey] || 0;
return dir === 'asc' ? va - vb : vb - va;
});
rows.forEach(r => tbody.appendChild(r));
}
headers.forEach((headerText, idx) => {
const th = document.createElement("th");
th.textContent = headerText;
// Add clickable unit toggle for Price and Supply headers
if (idx === 2) {
th.title = 'Total supply of ERC1155 CRC';
}
if (idx === 4 || idx === 5) {
const unitSpan = document.createElement('span');
unitSpan.className = 'unit-label';
unitSpan.textContent = showDemurraged ? 'CRC' : 's-CRC';
unitToggleLabels.push(unitSpan);
unitSpan.addEventListener('click', toggleUnit);
th.appendChild(unitSpan);
}
if (sortableColumns[idx]) {
th.className = 'sortable';
th.addEventListener('click', () => {
const newDir = (currentSort.col === idx && currentSort.dir === 'desc') ? 'asc' : 'desc';
currentSort = { col: idx, dir: newDir };
headerRow.querySelectorAll('th.sortable').forEach(h => h.classList.remove('sort-asc', 'sort-desc'));
th.classList.add(newDir === 'asc' ? 'sort-asc' : 'sort-desc');
sortTable(tbody, sortableColumns[idx], newDir);
});
}
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
// Create table body
const tbody = document.createElement("tbody");
// Helper: update a single row's display based on toggle state
function updateRowDisplay(row) {
const supplyFactor = showDemurraged ? staticToDemurragedFactor : 1;
const priceFactor = showDemurraged ? (1 / staticToDemurragedFactor) : 1;
const unit = showDemurraged ? ' CRC' : ' s-CRC';
const displaySupply = row.rawSupply * supplyFactor;
row.supplyCell.textContent = displaySupply.toLocaleString(undefined, { maximumFractionDigits: 2 }) + unit;
row.sortSupply = displaySupply;
if (row.rawPrice !== null) {
const displayPrice = row.rawPrice * priceFactor;
row.priceCell.textContent = displayPrice.toFixed(4);
row.priceCell.appendChild(row.pricePoolDiv);
row.sortPrice = displayPrice;
// Market cap = ERC1155 supply × price per CRC
const pricePerCRC = row.rawPrice / staticToDemurragedFactor;
row.sortMarketCap = row.rawErc1155Supply * pricePerCRC;
row.marketCapCell.textContent = row.sortMarketCap.toLocaleString(undefined, { maximumFractionDigits: 2 });
}
}
function updateAllRows() {
Array.from(tbody.querySelectorAll('tr')).forEach(updateRowDisplay);
if (currentSort.col !== null) {
sortTable(tbody, sortableColumns[currentSort.col], currentSort.dir);
}
}
// Add each group as a row
for (let i = 0; i < addresses.length; i++) {
const groupAddress = addresses[i];
const info = groups[i];
const row = document.createElement("tr");
// Helper function to truncate address
function truncateAddress(address) {
if (!address) return '';
return address.slice(0, 6) + '...' + address.slice(-4);
}
// Helper function to create address cell
const createAddressCell = (address, isGroupAddress = false, isService = false, isBaseMintHandler = false, noSafe = false, isERC20 = false) => {
const cell = document.createElement("td");
// Container for address and actions
const container = document.createElement("div");
container.className = "address-container";
// Main row: profile name (bold), address (truncated), actions
const mainRow = document.createElement("div");
mainRow.className = "address-main";
// Etherscan link (truncated address)
const etherscanLink = document.createElement("a");
etherscanLink.href = `https://gnosisscan.io/address/${address}`;
etherscanLink.target = "_blank";
etherscanLink.rel = "noopener noreferrer";
etherscanLink.textContent = truncateAddress(address);
etherscanLink.className = "address-link";
etherscanLink.title = address;
// Prevent Etherscan link from triggering any reload or group clearing
etherscanLink.onclick = (e) => { e.stopPropagation(); };
mainRow.appendChild(etherscanLink);
// Cowswap link for ERC20 tokens
if (isERC20) {
const cowBtn = document.createElement("button");
cowBtn.className = "icon-btn";
cowBtn.title = "Swap on CowSwap";
cowBtn.innerHTML = `<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='2 2 20 20'><path fill='#004293' fill-rule='evenodd' d='M9.827 18a2.005 2.005 0 0 1-1.912-1.395l-1.36-4.272H5.72a2.01 2.01 0 0 1-1.912-1.396L3 8.4h3.029L4.431 6H19.57l-1.6 2.4H21l-.808 2.538a2.005 2.005 0 0 1-1.912 1.395h-.835l-1.36 4.272A2.005 2.005 0 0 1 14.173 18zM8.8 11.166c0 .645.482 1.168 1.078 1.168c.595 0 1.078-.523 1.078-1.168c0-.643-.483-1.166-1.078-1.166S8.8 10.523 8.8 11.166m6.4 0c0 .645-.482 1.168-1.078 1.168c-.595 0-1.078-.523-1.078-1.168c0-.643.483-1.166 1.078-1.166s1.078.523 1.078 1.166' clip-rule='evenodd'/></svg>`;
cowBtn.onclick = (e) => {
e.preventDefault();
window.open(`https://swap.cow.fi/#/100/swap/WXDAI/${address}`, '_blank');
};
mainRow.appendChild(cowBtn);
}
// Profile button for group address
if (isGroupAddress) {
const profileBtn = document.createElement("button");
profileBtn.className = "icon-btn";
profileBtn.title = "Open Profile";
profileBtn.innerHTML = `<svg width="18" height="18" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="6.5" r="3.5" stroke="#191568" stroke-width="1.5"/><path d="M2.5 15c0-2.485 2.91-4.5 6.5-4.5s6.5 2.015 6.5 4.5" stroke="#191568" stroke-width="1.5" stroke-linecap="round"/></svg>`;
profileBtn.onclick = (e) => {
e.preventDefault();
window.open(`profileChecker.html?address=${address}`, '_blank');
};
mainRow.appendChild(profileBtn);
}
// Mint button for base mint handler
if (isBaseMintHandler) {
const mintBtn = document.createElement("button");
mintBtn.className = "mint-btn icon-btn";
mintBtn.title = "Mint via Gnosis";
mintBtn.innerHTML = `<svg width="18" height="18" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="9" r="7.5" stroke="#191568" stroke-width="1.5"/><path d="M9 5v8M5 9h8" stroke="#191568" stroke-width="1.5" stroke-linecap="round"/></svg>`;
mintBtn.onclick = (e) => {
e.preventDefault();
window.open(`https://app.gnosis.io/transfer/${address}/crc`, '_blank');
};
mainRow.appendChild(mintBtn);
}
// Safe button for other addresses (not group, not service, not base mint handler, not noSafe)
if (!isGroupAddress && !isService && !isBaseMintHandler && !noSafe) {
const safeBtn = document.createElement("button");
safeBtn.className = "icon-btn";
safeBtn.title = "Open in Safe";
safeBtn.innerHTML = `<svg width="18" height="18" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="5" width="12" height="8" rx="2" stroke="#191568" stroke-width="1.5"/><circle cx="9" cy="9" r="1.5" stroke="#191568" stroke-width="1.5"/></svg>`;
safeBtn.onclick = (e) => {
e.preventDefault();
window.open(`https://app.safe.global/home?safe=gno:${address}`, '_blank');
};
mainRow.appendChild(safeBtn);
}
// Copy button (icon) always on the right
const copyBtn = document.createElement("button");
copyBtn.className = "icon-btn";
copyBtn.title = "Copy Address";
copyBtn.innerHTML = `<svg width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="10" height="10" rx="2" stroke="#191568" stroke-width="1.5"/><rect x="6" y="6" width="7" height="7" rx="1.5" stroke="#191568" stroke-width="1.5"/></svg>`;
copyBtn.style.marginLeft = 'auto';
copyBtn.onclick = () => {
navigator.clipboard.writeText(address);
copyBtn.innerHTML = `<svg width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="10" height="10" rx="2" stroke="#191568" stroke-width="1.5"/><path d="M6 9l2 2 4-4" stroke="#191568" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
setTimeout(() => {
copyBtn.innerHTML = `<svg width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="3" width="10" height="10" rx="2" stroke="#191568" stroke-width="1.5"/><rect x="6" y="6" width="7" height="7" rx="1.5" stroke="#191568" stroke-width="1.5"/></svg>`;
}, 1500);
};
mainRow.appendChild(copyBtn);
container.appendChild(mainRow);
// Profile name (bold)
const nameSpan = document.createElement("span");
nameSpan.className = "profile-name";
nameSpan.setAttribute("data-address", address);
nameSpan.textContent = "Loading name...";
container.appendChild(nameSpan);
if (address !== "0x0000000000000000000000000000000000000000") {
getProfileName(address).then(name => {
nameSpan.textContent = name;
});
} else {
nameSpan.textContent = "None";
}
cell.appendChild(container);
return cell;
};
// Add cells to row
row.appendChild(createAddressCell(groupAddress, true));
row.appendChild(createAddressCell(info.owner));
// ERC1155 Total Supply
const erc1155SupplyVal = parseFloat(ethers.utils.formatEther(info.erc1155TotalSupply || 0));
row.sortErc1155Supply = erc1155SupplyVal;
row.appendChild(document.createElement('td')).textContent = erc1155SupplyVal.toLocaleString(undefined, { maximumFractionDigits: 2 });
// Static ERC20 (actually demurraged)
row.appendChild(createAddressCell(info.demurragedERC20, false, false, false, true, true));
// Static ERC20 Price
const staticPriceCell = document.createElement('td');
staticPriceCell.textContent = 'Loading...';
// Always create a poolDiv for Balancer icons
const staticPoolDiv = document.createElement('div');
staticPoolDiv.style.display = 'flex';
staticPoolDiv.style.gap = '4px';
staticPriceCell.appendChild(staticPoolDiv);
row.appendChild(staticPriceCell);
row.priceCell = staticPriceCell;
row.pricePoolDiv = staticPoolDiv;
row.rawPrice = null;
row.sortPrice = 0;
row.rawErc1155Supply = parseFloat(ethers.utils.formatEther(info.erc1155TotalSupply || 0));
row.demurragedERC20Address = info.demurragedERC20;
function updateStaticPools(pools, error) {
staticPoolDiv.innerHTML = '';
if (error) {
setTimeout(() => {
getPoolsForToken(info.demurragedERC20).then((p) => updateStaticPools(p, null)).catch(() => updateStaticPools([], true));
}, 5000);
return;
}
if (pools.length > 0) {
pools.forEach(pool => {
const balancerBtn = document.createElement('button');
balancerBtn.className = 'icon-btn';
balancerBtn.title = 'View on Balancer';
balancerBtn.innerHTML = `<svg width='22' height='22' viewBox='0 0 512 512' fill='none' xmlns='http://www.w3.org/2000/svg'><rect x='2' y='2' width='508' height='508' rx='254' fill='#004293'/><path d='M375.644 126.065C375.644 148.144 322.077 166.043 255.999 166.043C189.921 166.043 136.355 148.144 136.355 126.065C136.355 103.985 189.921 86.0862 255.999 86.0862C322.077 86.0862 375.644 103.985 375.644 126.065Z' fill='white'/><path d='M455.407 343.283C455.407 316.07 406.59 292.669 336.623 282.322L334.811 282.69C311.212 287.346 284.413 289.978 256 289.978C226.856 289.978 199.409 287.208 175.376 282.322C105.409 292.669 56.5918 316.07 56.5918 343.283C56.5918 380.082 145.869 409.914 256 409.914C366.13 409.914 455.407 380.082 455.407 343.283Z' fill='white'/><path d='M415.526 223.347C415.526 199.799 369.838 179.82 306.468 172.762L304.833 173.026C289.752 175.398 273.267 176.704 256 176.704C238.105 176.704 221.053 175.302 205.531 172.764C142.161 179.819 96.4734 199.801 96.4734 223.347C96.4734 252.786 167.895 276.652 256 276.652C344.104 276.652 415.526 252.786 415.526 223.347Z' fill='white'/><rect x='2' y='2' width='508' height='508' rx='254' stroke='#E5E7EB' stroke-width='4'/></svg>`;
balancerBtn.onclick = (e) => {
e.preventDefault();
window.open(`https://balancer.fi/pools/gnosis/v2/${pool.id}`, '_blank');
};
staticPoolDiv.appendChild(balancerBtn);
});
}
}
(function fetchStaticPools() {
getPoolsForToken(info.demurragedERC20)
.then(p => updateStaticPools(p, null))
.catch(() => updateStaticPools([], true));
})();
// Static ERC20 Supply
const staticSupplyVal = parseFloat(ethers.utils.formatEther(info.demurragedERC20TotalSupply || 0));
row.rawSupply = staticSupplyVal;
row.sortSupply = staticSupplyVal;
const supplyCell = document.createElement('td');
supplyCell.textContent = staticSupplyVal.toLocaleString(undefined, { maximumFractionDigits: 2 });
row.supplyCell = supplyCell;
row.appendChild(supplyCell);
// Market Cap (Price × Supply)
const marketCapCell = document.createElement('td');
marketCapCell.textContent = '...';
row.sortMarketCap = 0;
row.marketCapCell = marketCapCell;
row.appendChild(marketCapCell);
// Demurraged ERC20 (actually static)
row.appendChild(createAddressCell(info.staticERC20, false, false, false, true, true));
// Demurraged ERC20 Supply
const demurragedSupplyVal = parseFloat(ethers.utils.formatEther(info.staticERC20TotalSupply || 0));
row.sortDemurragedSupply = demurragedSupplyVal;
row.appendChild(document.createElement('td')).textContent = demurragedSupplyVal.toLocaleString(undefined, { maximumFractionDigits: 2 });
// Membership conditions
const conditionsCell = document.createElement('td');
if (info.membershipConditions.length > 0) {
const conditionsList = document.createElement('ul');
info.membershipConditions.forEach(condition => {
const li = document.createElement('li');
const link = document.createElement('a');
link.href = '#';
link.textContent = condition;
link.onclick = async (e) => {
e.preventDefault();
const profileName = await getProfileName(condition);
link.textContent = profileName || condition;
};
li.appendChild(link);
conditionsList.appendChild(li);
});
conditionsCell.appendChild(conditionsList);
} else {
conditionsCell.textContent = 'None';
}
row.appendChild(conditionsCell);
// Service, Base Mint Handler, Base Mint Policy, Base Treasury (rightmost)
row.appendChild(createAddressCell(info.service, false, true));
// Base Mint Handler cell with debug class
const baseMintHandlerCell = createAddressCell(info.baseMintHandler, false, false, true);
row.appendChild(baseMintHandlerCell);
row.appendChild(createAddressCell(info.baseMintPolicy, false, false, false, true));
row.appendChild(createAddressCell(info.baseTreasury, false, false, false, true));
row.appendChild(createAddressCell(info.feeCollection));
tbody.appendChild(row);
}
table.appendChild(tbody);
resultDiv.appendChild(table);
// Default sort by Supply descending, apply demurraged conversion
currentSort = { col: 5, dir: 'desc' };
headerRow.querySelectorAll('th.sortable').forEach(h => h.classList.remove('sort-asc', 'sort-desc'));
headerRow.children[5].classList.add('sort-desc');
updateAllRows();
// Fetch prices sequentially, sorted by largest supply first
// to be gentle with the Balancer API and avoid rate limiting
(async function fetchPricesSequentially() {
const rows = Array.from(tbody.querySelectorAll('tr'));
rows.sort((a, b) => (b.rawSupply || 0) - (a.rawSupply || 0));
for (const row of rows) {
// Fetch static ERC20 price (from demurraged ERC20 address)
if (row.demurragedERC20Address) {
const price = await getPrice(row.demurragedERC20Address);
if (price !== 'N/A') {
row.rawPrice = parseFloat(price) || 0;
updateRowDisplay(row);
if (currentSort.col === 4 || currentSort.col === 6) {
sortTable(tbody, sortableColumns[currentSort.col], currentSort.dir);
}
} else {
row.priceCell.textContent = 'N/A';
row.priceCell.appendChild(row.pricePoolDiv);
// Schedule retry later with longer delay
(function retryStaticPrice(r) {
setTimeout(async () => {
const p = await getPrice(r.demurragedERC20Address);
if (p !== 'N/A') {
r.rawPrice = parseFloat(p) || 0;
updateRowDisplay(r);
if (currentSort.col === 4 || currentSort.col === 6) {
sortTable(tbody, sortableColumns[currentSort.col], currentSort.dir);
}
} else {
retryStaticPrice(r);
}
}, 10000);
})(row);
}
// Gentle delay between API calls
await new Promise(res => setTimeout(res, 500));
}
}
})();
} catch (error) {
console.error(error);
resultDiv.innerHTML = `<p style='color:red;'>Error: ${error.message}</p>`;
}
}
checkButton.addEventListener("click", async () => {
const input = groupInput.value.trim();
await checkGroups(input);
});
// When clicking on any displayed address, set it as the input and re-run the check.
resultDiv.addEventListener("click", async (e) => {
if (e.target.classList.contains("address-link")) {
const addr = e.target.getAttribute("data-address");
groupInput.value = addr;
await checkGroups(addr);
}
});
// Initialize the input with trusted groups on page load
async function initializePage() {
// this is the address of the gnosis truster org
const trusterAddress =
"0x0afd8899bca011bb95611409f09c8efbf6b169cf";
const trustedGroups = await fetchTrustedGroups(trusterAddress);
// Add extra groups not covered by the truster
const extraGroups = ['0x86533d1aDA8Ffbe7b6F7244F9A1b707f7f3e239b'];
extraGroups.forEach(g => { if (!trustedGroups.includes(g)) trustedGroups.push(g); });
if (trustedGroups.length > 0) {
groupInput.value = trustedGroups.join(", ");
// Automatically trigger the check
await checkGroups(groupInput.value);
}
}
// Call initializePage when the document is ready
document.addEventListener("DOMContentLoaded", initializePage);
function displayGroupInfo(groups) {
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
const table = document.createElement('table');
table.className = 'group-table';
// Create table headers
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
const headers = [
'Group Address', 'Owner', 'Total Supply',
'Service',
'Base Mint Handler', 'Base Mint Policy', 'Base Treasury',
'Static ERC20', 'Static ERC20 Price', 'Static ERC20 Supply',
'Membership Conditions', 'Fee Collection'
];
headers.forEach(headerText => {
const th = document.createElement('th');
th.textContent = headerText;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
// Create table body
const tbody = document.createElement('tbody');
groups.forEach(group => {
const row = document.createElement('tr');
// Helper function to add a cell with address handling
const addRow = (value, isAddress = false) => {
const cell = document.createElement('td');
if (isAddress && value !== '0x0000000000000000000000000000000000000000') {
const link = document.createElement('a');
link.href = '#';
link.textContent = value;
link.onclick = async (e) => {
e.preventDefault();
const profileName = await getProfileName(value);
link.textContent = profileName || value;
};
cell.appendChild(link);
} else {
cell.textContent = value;
}
row.appendChild(cell);
};
// Add all fields
addRow(group.groupAddress, true);
addRow(group.owner, true);
addRow(ethers.utils.formatEther(group.erc1155TotalSupply || 0));
addRow(group.service, true);
addRow(group.baseMintHandler, true);
addRow(group.baseMintPolicy, true);
addRow(group.baseTreasury, true);
addRow(group.staticERC20, true);
addRow(ethers.utils.formatEther(group.staticERC20TotalSupply || 0));
// Add membership conditions
const conditionsCell = document.createElement('td');
if (group.membershipConditions && group.membershipConditions.length > 0) {
const conditionsList = document.createElement('ul');
group.membershipConditions.forEach(condition => {
const li = document.createElement('li');
const link = document.createElement('a');
link.href = '#';