Skip to content

Instantly share code, notes, and snippets.

@lljxx1
Last active June 20, 2022 17:43
Show Gist options
  • Save lljxx1/b1369cae021b73c84a76f43acd8328b9 to your computer and use it in GitHub Desktop.
Save lljxx1/b1369cae021b73c84a76f43acd8328b9 to your computer and use it in GitHub Desktop.
const ethers = require("ethers");
const readline = require("readline");
const fs = require("fs");
const { Multicall } = require("ethereum-multicall");
let provider = new ethers.providers.StaticJsonRpcProvider(
"https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
);
const multicall = new Multicall({
ethersProvider: provider,
tryAggregate: true,
});
const chunk = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
arr.slice(i * size, i * size + size)
);
const allColumns = [
{ index: 0, column: "address" },
{ index: 1, column: "eth" },
{ index: 2, column: "usd" },
{ index: 3, column: "count" },
{ index: 4, column: "lastBlock" },
{ index: 5, column: "tokens" },
{ index: 6, column: "amount" },
{ index: 7, column: "proof" },
{ index: 8, column: "amount_decimal" },
];
async function isClaimed(accounts) {
const contractCallContext = [
{
reference: "gasDAO",
contractAddress: "0x6bba316c48b49bd1eac44573c5c871ff02958469",
abi: [
{
inputs: [
{
internalType: "address",
name: "account",
type: "address",
},
],
name: "hasClaimed",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
},
],
calls: accounts.map((_) => {
return {
reference: "fooCall",
methodName: "hasClaimed",
methodParameters: [_],
};
}),
context: {
extraContext: "extraContext",
foo4: true,
},
},
];
const resp = await multicall.call(contractCallContext);
const allResults = resp.results.gasDAO.callsReturnContext.map((_) => {
return {
address: _.methodParameters[0],
claimed: _.returnValues[0],
};
});
// console.log(allResults);
return allResults;
}
async function checkClaim(allAccounts) {
const stepItems = chunk(allAccounts, 50);
const counts = {
claimed: 0,
wait: 0,
total: 0,
};
console.log(stepItems.length, allAccounts.length);
for (let index = 0; index < stepItems.length; index++) {
const items = stepItems[index];
const stepResult = await isClaimed(items.map((_) => _.address));
stepResult.forEach((_) => {
if (_.claimed) {
counts.claimed++;
} else {
counts.wait++;
}
counts.total++;
counts.claim_rate = (counts.claimed / counts.total) * 100;
});
console.log(counts);
}
}
const TOKEN_PRICE = 0.00011112;
const valueLimit = 500;
const counts = {
above: 0,
sumValue: 0,
};
const aboveAccounts = [];
async function processLineByLine() {
// https://s3.wasabisys.com/gasdao/airdrop_final.csv.zip
const fileStream = fs.createReadStream(
"./airdrop_final.csv"
);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
for await (const line of rl) {
const rows = line.split(",");
const tokenValue = rows;
// console.log(rows.map((_, index) => ({ index: index, column: _})));
const address = rows[0];
const tokens = rows[5];
const tokensValue = TOKEN_PRICE * tokens;
const feeSpend = rows[2];
if (tokensValue > valueLimit) {
counts.above++;
counts.sumValue += tokensValue;
// console.log({
// address,
// tokens,
// tokensValue,
// });
aboveAccounts.push({
address,
tokens,
tokensValue,
feeSpend,
});
}
}
console.log(counts);
await checkClaim(aboveAccounts);
}
processLineByLine();
// tokenPrice = 0.00011112;
// tokenValue = tokens * tokenPrice
// tokenValue > 200
// { claimed: 33021, wait: 39419, total: 72440, claim_rate: 45.58 }
@cryptoY11
Copy link

厉害了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment