Skip to content

Instantly share code, notes, and snippets.

@DistributedDoge
Last active February 26, 2024 03:04
Show Gist options
  • Save DistributedDoge/7634f4346980826c28e165167d5922d0 to your computer and use it in GitHub Desktop.
Save DistributedDoge/7634f4346980826c28e165167d5922d0 to your computer and use it in GitHub Desktop.
[old] Get and decode all Gitcoin grant round Voted events up-till now.
-- Google Big Query... query(?) to catch all Events emitted by successful donations to old Gitcoin grant round. No matter what contract/round is emitting them.
-- In post-processing might be prudent to check that only official Gitcoin grant rounds are emitting such events.
-- Event ABI corresponds to `Voted` event emitted by QuadraticFundingVotingStrategyImplementation
-- https://etherscan.io/tx/0x02d062a8605c518b07343230b35d9aa23c3781a65e58d45a71ffb607a8b00ced#eventlog
-- NOTE: Won't work for recent Gicoin rounds as ABI has changed.
-- Voted (address token, uint256 amount, index_topic_1 address voter, address grantAddress, index_topic_2 bytes32 projectId, uint256 applicationIndex, index_topic_3 address roundAddress)
CREATE TEMP FUNCTION
DECODE_LOG(data STRING, topics ARRAY<STRING>)
RETURNS STRUCT<`voter` STRING, `token` STRING, `roundAddress` STRING, `amount` STRING, `grantAddress` STRING, `projectId` STRING, `applicationIndex` STRING>
LANGUAGE js AS """
var EVENT_ABI = {"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"voter","type":"address"},{"indexed":false,"internalType":"address","name":"grantAddress","type":"address"},{"indexed":true,"internalType":"bytes32","name":"projectId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"applicationIndex","type":"uint256"},{"indexed":true,"internalType":"address","name":"roundAddress","type":"address"}],"name":"Voted","type":"event"};
var interface_instance = new ethers.utils.Interface([EVENT_ABI]);
var parsedLog = interface_instance.parseLog({topics: topics, data: data});
return parsedLog.values;
"""
OPTIONS
( library="gs://blockchain-etl-bigquery/ethers.js" );
SELECT
voter,
voted.token,
voted.roundAddress,
voted.amount,
voted.grantAddress,
voted.projectId,
voted.applicationIndex,
address AS log_address,
transaction_hash AS tx_hash,
block_timestamp
FROM
`bigquery-public-data.crypto_ethereum.logs`,
UNNEST([DECODE_LOG(data, topics)]) AS voted
WHERE
topics[SAFE_OFFSET(0)] = "0x0064caa73f1d59b69adbeb65654b0f0953597994e4241ee2460b560b8d65aaa2"
AND DATE(block_timestamp) > '2023-04-23';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment