Skip to content

Commit

Permalink
fix: parse epoch string to number
Browse files Browse the repository at this point in the history
  • Loading branch information
longpv15 committed Mar 6, 2024
1 parent e752042 commit 330fad5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/execute/executeStakerReward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const processExportByEpoch = async (
argv.output
);

if (epoch < result.epoch) {
if (Number(epoch) < Number(result.epoch)) {
return;
}

Expand Down
11 changes: 6 additions & 5 deletions src/execute/executeValidatorReward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ const processExportByEpoch = async (
'commission-reward',
argv.output,
);


if (epoch < result.epoch) {
if (Number(epoch) < Number(result.epoch)) {
return;
}

Expand All @@ -156,7 +157,7 @@ const processExportByEpoch = async (
block,
validatorAddress,
);

const { rowData } = getAdditionalDataForCommissionReward(
oasPrices,
validatorStake,
Expand All @@ -165,7 +166,7 @@ const processExportByEpoch = async (
validatorAddress,
priceTime,
);

await sleep(100);

return {
Expand All @@ -183,7 +184,7 @@ const processExportByEpoch = async (
}

const dataExport = await Promise.all(promises);

// process export
await exportCsv(
dataExport,
Expand All @@ -193,7 +194,7 @@ const processExportByEpoch = async (
header,
doc,
);
const totalSecondsEpoch = getTotalSecondProcess(startTimeProcess);
const totalSecondsEpoch = getTotalSecondProcess(startTimeProcess);
console.info(
`-->Export at Epoch ${epoch} took ${totalSecondsEpoch} seconds`,
);
Expand Down
4 changes: 2 additions & 2 deletions src/module/RewardStakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const getAdditionalDataForCommissionReward = (
const rowData = stakeData
.filter((stake) => {
const validatorTotalStake = stake.oas.add(stake.soas).add(stake.woas);
return validatorTotalStake.gt(0);
return validatorTotalStake;
})
.map((stake) => {
totalStake = totalStake.add(stake.oas).add(stake.soas).add(stake.woas);
Expand Down Expand Up @@ -290,7 +290,7 @@ export const getAdditionalDataForStakerReward = (
address,
epoch,
block,
timestamp.format('YYYY-MM-DD HH:mm:ss'),
timestamp.format('YYYY/MM/DD HH:mm:ss'),
utils.formatEther(stakeData.totalStake).toString(),
utils.formatEther(stakeData.stakerReward).toString(),
...prices,
Expand Down
12 changes: 11 additions & 1 deletion src/utils/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ export class Subgraph {
};

const data = await request(this.baseGraphUrl, GetValidators, variables);
if (data?.validators?.length == 0) {
return {
validators: [
{
id: validator_address,
commissions: '0',
},
],
};
}
return data;
};
public getValidatorStakes = async (validator: string, block: number) => {
Expand All @@ -257,7 +267,7 @@ export class Subgraph {
variables,
);

if (data.validators[0].stakes.length === 0) break; // All stake information already retrieved.
if (!data.validators[0] || data.validators[0].stakes.length === 0) break; // All stake information already retrieved.
validatorStakes.validators[0].stakes =
validatorStakes.validators[0].stakes.concat(data.validators[0].stakes);
}
Expand Down

0 comments on commit 330fad5

Please sign in to comment.