Created
January 24, 2023 00:24
-
-
Save VeryCB/ae0e3c551c3a6846cd3ccd46ecae0dce to your computer and use it in GitHub Desktop.
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
import ethers from 'ethers' | |
import _ from 'underscore' | |
import dotenv from 'dotenv' | |
dotenv.config() | |
const delay = (time) => { | |
return new Promise((resolve) => setTimeout(resolve, time)) | |
} | |
const provider = new ethers.providers.JsonRpcProvider(process.env.MAINNET_RPC) | |
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY) | |
const account = wallet.connect(provider) | |
const abi = [ | |
'event Minted(address indexed to, bytes32 hashId, uint256 charId, uint256 bagId)', | |
] | |
const iface = new ethers.utils.Interface(abi) | |
const startBlock = 15654171 | |
const endBlock = 15663338 | |
const oldFilter = { | |
address: '0xf700013344D33A24C5d7907969B84CBa9C6468f0', // Old contract | |
fromBlock: startBlock, | |
toBlock: endBlock, | |
topics: [ | |
'0x1eba155afe217abd462a2edbeadbfc49bcc9c9fb4ea11f28992964f6527c518e', | |
], | |
} | |
const nftABI = [ | |
'function balanceOf(address owner) external view returns (uint256 balance)', | |
] | |
const nftAddress = '0x1a92f7381b9f03921564a437210bb9396471050c' // Cool Cats | |
const nft = new ethers.Contract(nftAddress, nftABI, account) | |
const petsAddress = '0x86c10d10eca1fca9daf87a279abccabe0063f247' // Cool Pets | |
const pets = new ethers.Contract(petsAddress, nftABI, account) | |
const checkBalance = async (address) => { | |
const balance = await nft.balanceOf(address) | |
const petBalance = await pets.balanceOf(address) | |
console.log(`${address} balance: ${balance}, pets balance: ${petBalance}`) | |
return { address, balance, petBalance } | |
} | |
const check = async () => { | |
const minters = new Set() | |
const logs = await provider.getLogs(oldFilter) | |
for (const log of logs) { | |
const parsed = iface.parseLog(log) | |
const [address, hashId, charId, bagId] = parsed.args | |
minters.add(address) | |
} | |
console.log(`Total minters: ${minters.size}`) | |
const mintersArray = Array.from(minters) | |
const chunks = _.chunk(mintersArray, 8) | |
let result = [] | |
for (const chunk of chunks) { | |
const tasks = chunk.map(checkBalance) | |
const _result = await Promise.all(tasks) | |
result = result.concat(_result) | |
await delay(1000) | |
} | |
const hasCoolCatOrPet = result.filter( | |
(r) => r.balance > 0 || r.petBalance > 0 | |
) | |
console.log(hasCoolCatOrPet.length) | |
} | |
check() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment