-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
140 lines (111 loc) · 4.3 KB
/
index.ts
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
import { computePublishedContractAddress } from "thirdweb/deploys";
import { sepolia } from "thirdweb/chains";
import dedent from "dedent";
import { createThirdwebClient } from "thirdweb";
import "dotenv/config";
const secret = process.env.SECRET!;
const client = createThirdwebClient({
// use `secretKey` for server side or script usage
secretKey: secret,
});
const erc20 = [
"ClaimableERC20",
"MintableERC20",
"TransferableERC20",
"CreatorTokenERC20",
];
const erc721 = [
"BatchMetadataERC721",
"ClaimableERC721",
"MintableERC721",
"OpenEditionMetadataERC721",
"RoyaltyERC721",
"TransferableERC721"
];
const erc1155 = [
"BatchMetadataERC1155",
"ClaimableERC1155",
"MintableERC1155",
"OpenEditionMetadataERC1155",
"RoyaltyERC1155",
"TransferableERC1155",
"SequentialTokenIdERC1155",
];
const allModules = [...erc20, ...erc721, ...erc1155];
const moduleInstalledTopic0 = "0xbcd03fe408dcc45614e803cbab9f500dddff61b17380b993e76d30398da47229"
const moduleUninstalledTopic0 = "0xef3b2e20acbb62d61d782c5449bd73d3970cb9be1050a6ad6f846b2cbe21c03a"
const installModuleTableName = 'install_module_logs'
const uninstallModuleTableName = 'uninstall_module_logs'
const tableTemplate = (name: string, topic0: string) => dedent`
WITH ${name} AS (
SELECT
chain_id, data
FROM logs
WHERE chain_id IN (137, 11155111, 8453, 42161, 43113, 660279, 534352, 59144, 7777777)
AND topic_0 = '${topic0}'
)`
const queryTemplate = (filters: string, table: string) => dedent`
SELECT
${filters}
FROM ${table};
`
const countFilterTemplate = (contract: string, module: string, last: boolean) => `countIf(data LIKE '%${contract}') AS ${module}${last ? '' : ','}`;
const getAddress = (module: string) => computePublishedContractAddress({
client,
chain: sepolia,
contractId: module,
});
const getErcFilters = (erc: string[]) => Promise.all(erc.map(async (module, i) => {
const address = await getAddress(module);
return countFilterTemplate(address.slice(2), module, i === erc.length - 1);
}))
async function typesOfModulesInstalledAndUninstalledByERC() {
const installModuleTable = tableTemplate(installModuleTableName, moduleInstalledTopic0);
const uninstallModuleTable = tableTemplate(uninstallModuleTableName, moduleUninstalledTopic0);
const erc20Filters = (await getErcFilters(erc20)).join("\n");
const erc721Filters = (await getErcFilters(erc721)).join("\n");
const erc1155Filters = (await getErcFilters(erc1155)).join("\n");
const moduleInstalledErc20 = queryTemplate(erc20Filters, installModuleTableName);
const moduleInstalledErc721 = queryTemplate(erc721Filters, installModuleTableName);
const moduleInstalledErc1155 = queryTemplate(erc1155Filters, installModuleTableName);
const moduleUninstalledErc20 = queryTemplate(erc20Filters, uninstallModuleTableName);
const moduleUninstalledErc721 = queryTemplate(erc721Filters, uninstallModuleTableName);
const moduleUninstalledErc1155 = queryTemplate(erc1155Filters, uninstallModuleTableName);
console.log(installModuleTable);
console.log(moduleInstalledErc20);
console.log();
console.log(installModuleTable);
console.log(moduleInstalledErc721);
console.log();
console.log(installModuleTable);
console.log(moduleInstalledErc1155);
console.log();
console.log(uninstallModuleTable);
console.log(moduleUninstalledErc20);
console.log();
console.log(uninstallModuleTable);
console.log(moduleUninstalledErc721);
console.log();
console.log(uninstallModuleTable);
console.log(moduleUninstalledErc1155);
console.log();
}
// =============================================================================
const customModuleQueryTemplate = (filter: string) => dedent`
SELECT
COUNT(DISTINCT(substring(data, -40)))
FROM logs
WHERE chain_id IN (137, 11155111, 8453, 42161, 43113, 660279, 534352, 59144, 7777777)
${filter}
`
const customModuleFilter = (contract: string) => `AND data NOT LIKE '%${contract}'`;
async function numberOfCustomModules() {
const allModulesFilter = (await Promise.all(allModules.map(async (module) => {
const address = await getAddress(module);
return customModuleFilter(address.slice(2))
}))).join("\n");
const customModuleQuery = customModuleQueryTemplate(allModulesFilter);
console.log(customModuleQuery);
}
//typesOfModulesInstalledAndUninstalledByERC();
numberOfCustomModules();