Skip to content

Instantly share code, notes, and snippets.

@Elyx0
Created January 20, 2023 07:24
Show Gist options
  • Save Elyx0/f698f8135046c170afca2c7f07687efb to your computer and use it in GitHub Desktop.
Save Elyx0/f698f8135046c170afca2c7f07687efb to your computer and use it in GitHub Desktop.
OFAC Polygon List
// Never thought I'd have to, I'm sorry Elyx from the past
const ethers = require('ethers');
const RPC = "https://polygon.llamarpc.com";
const provider = new ethers.providers.JsonRpcProvider(RPC);
const interface = new ethers.utils.Interface([
"event SanctionedAddressesAdded(address[] addrs)",
"event SanctionedAddressesRemoved(address[] addrs)"
]);
const ofacCreatedBlock = 25790842;
const OFAC_POLYGON = "0x40c57923924b5c5c5455c48d93317139addac8fb";
const OFAC_CONTRACT = new ethers.Contract(OFAC_POLYGON, interface, provider);
const SANCTIONNED_TOPIC = interface.getEventTopic(interface.events["SanctionedAddressesAdded(address[])"]);
const UNSANCTIONNED_TOPIC = interface.getEventTopic(interface.events["SanctionedAddressesRemoved(address[])"]);
const eventFilter = {};
const OFAC_LIST = {};
async function main() {
const results = await OFAC_CONTRACT.queryFilter(eventFilter,ofacCreatedBlock);
console.log(results);
for (const result of results) {
if (result.topics.includes(SANCTIONNED_TOPIC)) {
console.log(result.blockHash, 'block added sanctions');
result.decode(result.data,result.topics).forEach(k => {
OFAC_LIST[k] = true;
});
}
if (result.topics.includes(UNSANCTIONNED_TOPIC)) {
console.log(result.blockHash, 'block removed sanctions');
result.decode(result.data,result.topics).forEach(k => {
OFAC_LIST[k] = false;
});
}
}
const filtered_list = Object.keys(OFAC_LIST).filter(k => OFAC_LIST[k]);
console.log(filtered_list);
}
main().catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment