Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading public repo automatically #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion delegationsAPRs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sdcrv.eth":34.12526495082819,"sdbal.eth":31.011588601463995,"sdfxs.eth":3.7602201126563704}
{"sdcrv.eth":27.58064061677252,"sdbal.eth":23.60110471448226,"sdfxs.eth":4.853067510542256}
62 changes: 42 additions & 20 deletions generateMerkle.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const abi = parseAbi([

const main = async () => {

const csvResult = extractCSV();

const csvResult = await extractCSV();
// Fetch last merkle
const { data: lastMerkles } = await axios.get("https://raw.githubusercontent.com/StakeDAO/bribes/main/merkle.json");

Expand All @@ -86,7 +86,7 @@ const main = async () => {
checkSpace(space);

// If no bribe to distribute to this space => skip
if(!csvResult[space]) {
if (!csvResult[space]) {
continue;
}

Expand Down Expand Up @@ -215,14 +215,14 @@ const main = async () => {
const ratioVp = vp * 100 / delegatorSumVotingPower;

// This user should receive ratioVp% of all rewards
if(space === SDCRV_SPACE && delegatorAddress.toLowerCase() === "0x1c0d72a330f2768daf718def8a19bab019eead09".toLowerCase()) {
console.log("Concentrator vp : ", vp);
console.log("Delegation vp : ", delegatorSumVotingPower)
console.log("Total rewards : ", delegationVote.totalRewards);
console.log("Ratio % : ", ratioVp)
console.log("Ratio rewards : ", ratioVp * delegationVote.totalRewards / 100)
console.log("Ratio rewards new : ",vp * delegationVote.totalRewards / delegatorSumVotingPower)
if (space === SDCRV_SPACE && delegatorAddress.toLowerCase() === "0x1c0d72a330f2768daf718def8a19bab019eead09".toLowerCase()) {
console.log("Concentrator vp : ", vp);
console.log("Delegation vp : ", delegatorSumVotingPower)
console.log("Total rewards : ", delegationVote.totalRewards);
console.log("Ratio % : ", ratioVp)
console.log("Ratio rewards : ", ratioVp * delegationVote.totalRewards / 100)
console.log("Ratio rewards new : ", vp * delegationVote.totalRewards / delegatorSumVotingPower)

}
delegationVote.delegation[delegatorAddress.toLowerCase()] = ratioVp * delegationVote.totalRewards / 100;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ const main = async () => {
// Since this point, userRewards map contains the new reward amount for each user
// We have to generate the merkle
const userRewardAddresses = Object.keys(userRewards);

const elements = [];
for (let i = 0; i < userRewardAddresses.length; i++) {
const userAddress = userRewardAddresses[i];
Expand Down Expand Up @@ -346,7 +346,7 @@ const main = async () => {
functionName: 'multiSet',
args: [toFreeze, toSet],
})

console.log("To freeze :");
console.log("Contract : " + STASH_CONTROLLER_ADDRESS);
console.log("Data : ");
Expand Down Expand Up @@ -376,18 +376,40 @@ const main = async () => {
fs.writeFileSync(`./delegationsAPRs.json`, JSON.stringify(delegationAPRs));
}

const extractCSV = () => {
const cvsFile = fs.readFileSync("./report.csv");
let records = parse(cvsFile, {
const extractCSV = async () => {
const reportDir = 'https://raw.githubusercontent.com/stake-dao/bounties-report/main/';

// Get the list of files in the repository
const { data: files } = await axios.get('https://api.github.com/repos/stake-dao/bounties-report/contents');

// Filter out the CSV files
const csvFiles = files.filter(file => file.name.endsWith('.csv'));

// Sort the CSV files based on the date in the filename
const sortedCsvFiles = csvFiles.sort((a, b) => {
const dateA = a.name.split('_')[1].split('-').reverse().join('-');
const dateB = b.name.split('_')[1].split('-').reverse().join('-');
return new Date(dateB) - new Date(dateA);
});

console.log("Using : " + sortedCsvFiles[0].name);

// Get the most recent CSV file
const mostRecentCsvFile = sortedCsvFiles[0].name;

// Fetch the CSV file from the GitHub repository
const { data: csvFile } = await axios.get(reportDir + mostRecentCsvFile);

let records = parse(csvFile, {
columns: true,
skip_empty_lines: true,
delimiter: ";",
});

const newRecords = [];
for(const row of records) {
for (const row of records) {
let obj = {};
for(const key of Object.keys(row)) {
for (const key of Object.keys(row)) {
obj[key.toLowerCase()] = row[key];
}
newRecords.push(obj);
Expand Down Expand Up @@ -673,7 +695,7 @@ const extractProposalChoices = (proposal) => {
const addressesPerChoice = {};
for (let i = 0; i < proposal.choices.length; i++) {
const choice = proposal.choices[i];
if(choice.indexOf("Current Weights") > -1 || choice.indexOf("Paste") > -1 || choice.indexOf("Total Percentage") > -1) {
if (choice.indexOf("Current Weights") > -1 || choice.indexOf("Paste") > -1 || choice.indexOf("Total Percentage") > -1) {
continue;
}
const start = choice.indexOf(" - 0x");
Expand All @@ -700,7 +722,7 @@ const getChoiceWhereExistsBribe = (addressesPerChoice, cvsResult) => {
}

const cvsResultLowerCase = {};
for(const key of Object.keys(cvsResult)) {
for (const key of Object.keys(cvsResult)) {
cvsResultLowerCase[key.toLowerCase()] = cvsResult[key];
}

Expand Down
Loading