Created
January 20, 2023 07:24
-
-
Save Elyx0/f698f8135046c170afca2c7f07687efb to your computer and use it in GitHub Desktop.
OFAC Polygon List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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