Skip to content

Commit

Permalink
Merge pull request #2676 from Sifchain/scripts/update-reward-period-g…
Browse files Browse the repository at this point in the history
…enerator

chore: 🤖 update script to include past periods
  • Loading branch information
canercandan authored Apr 25, 2022
2 parents ed41a8f + 7503a59 commit 893cde9
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions scripts/rewards/rewards-period.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

const fs = require("fs");

async function createAssetRewardsFile() {
const csv = fs.readFileSync("./pools.csv", "utf-8");
async function createAssetRewardsFile(periodId, startBlock, endBlock) {
const csv = fs.readFileSync(`./${periodId}.csv`, "utf-8");
const entries = JSON.parse(fs.readFileSync("./entries.json", "utf-8")).result
.registry.entries;
const lines = csv.split("\r\n").filter((line) => line.split(",")[1] !== "");

let [, allocation] = lines[0].split('"');
let [, allocation] = lines[1].split('"');
allocation = `${allocation.trim().split(",").join("")}${"0".repeat(18)}`;

const multipliers = lines.slice(1).map((line) => {
Expand All @@ -30,22 +30,25 @@ async function createAssetRewardsFile() {
};
});

const rewards = [
{
reward_period_id: "RP_1",
reward_period_start_block: 1,
reward_period_end_block: 100,
reward_period_allocation: allocation,
reward_period_pool_multipliers: multipliers,
reward_period_default_multiplier: "0.0",
},
];
const rewardPeriod = {
reward_period_id: periodId,
reward_period_start_block: startBlock,
reward_period_end_block: endBlock,
reward_period_allocation: allocation,
reward_period_pool_multipliers: multipliers,
reward_period_default_multiplier: "0.0",
};

fs.writeFileSync("./rewards.json", JSON.stringify(rewards, null, 2));
return rewardPeriod;
}

async function start() {
await createAssetRewardsFile();
const rewardPeriods = [
await createAssetRewardsFile("RP_2", 6586931, 6687730),
await createAssetRewardsFile("RP_1", 6486131, 6586930),
];

fs.writeFileSync("./rewards.json", JSON.stringify(rewardPeriods, null, 2));
}

start();

0 comments on commit 893cde9

Please sign in to comment.