on df0c310 help sign in
bridge/find-gas-usage.js
114 lines 3.1 kB history raw
1// usage: tweak constants at head of file, then run "node find-gas-usage.js"
2// for very common events/calls, you may need to use a smaller TO-FROM
3// range to keep web3 from yelling at you
5const ORIGIN = 6784800; // launch ceremony begins
6const PUBLIC = 7033765; // azimuth becomes public
7const LATEST = 'latest';
8const AZIMUTH_ADDRESS = '0x223c067f8cf28ae173ee5cafea60ca44c335fecb';
9const ENDPOINT =
10 'https://mainnet.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87';
12const FROM = ORIGIN;
13const TO = LATEST;
15const VENT = 'ChangedKeys';
16const FUNC = '0x4447e48c'; // configureKeys
17const ARGS = 5;
19// const VENT = 'Spawned';
20// const FUNC = '0xa0d3253f'; // spawn
21// const ARGS = 2;
23// const VENT = 'OwnerChanged';
24// const FUNC = '0x1e79a85b'; // transferPoint
25// const ARGS = 3;
27// const VENT = 'ChangedSpawnProxy';
28// const FUNC = '0xae326221'; // setSpawnProxy
29// const ARGS = 2;
31// const VENT = 'ChangedManagementProxy';
32// const FUNC = '0x8866bb2c'; // setManagementProxy
33// const ARGS = 2;
35// const VENT = 'ChangedTransferProxy';
36// const FUNC = '0x2c7ba564'; // setTransferProxy
37// const ARGS = 2;
39// const VENT = 'ChangedVotingProxy';
40// const FUNC = '0xa60e8bd6'; // setVotingProxy
41// const ARGS = 2;
43// const VENT = 'EscapeRequested';
44// const FUNC = '0xbf5772b9'; // escape
45// const ARGS = 2;
47// const VENT = 'EscapeCanceled';
48// const FUNC = '0xc6d761d4'; // cancelEscape
49// const ARGS = 1;
51// const VENT = 'EscapeAccepted';
52// const FUNC = '0xc1b9d98b'; // adopt
53// const ARGS = 1;
55// const VENT = 'EscapeCanceled';
56// const FUNC = '0xbbe21ca5'; // reject
57// const ARGS = 1;
59// const VENT = 'LostSponsor';
60// const FUNC = '0x073a7804'; // detach
61// const ARGS = 1;
63const LENT = 64 * ARGS + FUNC.length;
65const Web3 = require('web3');
66const azimuth = require('azimuth-js');
68(async () => {
69 const web3 = new Web3(new Web3.providers.HttpProvider(ENDPOINT));
70 const contracts = await azimuth.initContractsPartial(web3, AZIMUTH_ADDRESS);
72 const keyEvents = await contracts.azimuth.getPastEvents(VENT, {
73 fromBlock: FROM,
74 toBlock: TO,
75 });
77 const txsBatch = new web3.BatchRequest();
78 keyEvents.map(vent => {
79 txsBatch.add(
80 web3.eth.getTransaction.request(vent.transactionHash, (err, res) => {})
81 );
82 });
83 const txs = await txsBatch.execute();
84 const keyTxs = txs.response.filter(tx => {
85 const head = tx.input.slice(0, 10) === FUNC;
86 const size = tx.input.length === LENT;
87 if (head && !size) {
88 console.log('weird inputs', tx.hash);
89 }
90 return head && size;
91 });
93 const receiptsBatch = new web3.BatchRequest();
94 keyTxs.map(tx => {
95 receiptsBatch.add(
96 web3.eth.getTransactionReceipt.request(tx.hash, (err, res) => {})
97 );
98 });
99 const recs = await receiptsBatch.execute();
101 let usage = {};
102 recs.response.map(rec => {
103 if (rec.status !== true) {
104 console.log('rejecting', rec.gasUsed);
105 return;
106 }
107 if (rec.gasUsed in usage) {
108 usage[rec.gasUsed]++;
109 } else {
110 usage[rec.gasUsed] = 1;
111 }
112 });
113 console.log(usage);
114})();