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

Patch #473

Merged
merged 4 commits into from
Feb 12, 2020
Merged

Patch #473

Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { insertVote } from './vote';

function isProposalValid(proposalId: string ): boolean {
let p = Proposal.load(proposalId);
return ((p != null) && (equalsBytes(p.paramsHash, new Bytes(32)) === false));
return ((p != null) && (equalsBytes(p.paramsHash, new Bytes(32)) == false));
}

function handleGPProposalPrivate(proposalId: string): void {
Expand Down Expand Up @@ -138,7 +138,7 @@ export function handleStake(event: Stake): void {
if (equalsBytes(proposal.paramsHash, new Bytes(32))) {
return;
}
if (event.params._vote.toI32() === 1) {
if (event.params._vote.toI32() == 1) {
proposal.stakesFor = proposal.stakesFor.plus(event.params._amount);
} else {
proposal.stakesAgainst = proposal.stakesAgainst.plus(event.params._amount);
Expand All @@ -163,7 +163,7 @@ export function handleVoteProposal(event: VoteProposal): void {
if (equalsBytes(proposal.paramsHash, new Bytes(32))) {
return;
}
if (event.params._vote.toI32() === 1) {
if (event.params._vote.toI32() == 1) {
proposal.votesFor = proposal.votesFor.plus(event.params._reputation);
} else {
proposal.votesAgainst = proposal.votesAgainst.plus(
Expand Down Expand Up @@ -273,8 +273,8 @@ export function handleExecuteProposal(event: ExecuteProposal): void {
export function handleStateChange(event: StateChange): void {
if (isProposalValid(event.params._proposalId.toHex())) {
updateProposalState(event.params._proposalId, event.params._proposalState, event.address);
if ((event.params._proposalState === 1) ||
(event.params._proposalState === 2)) {
if ((event.params._proposalState == 1) ||
(event.params._proposalState == 2)) {
insertGPRewards(event.params._proposalId, event.block.timestamp, event.address, event.params._proposalState);
}

Expand All @@ -290,9 +290,9 @@ export function handleExecutionStateChange(event: GPExecuteProposal): void {

export function handleGPRedemption(proposalId: Bytes, beneficiary: Address , timestamp: BigInt , type: string): void {
if (isProposalValid(proposalId.toHex())) {
if (type === 'token') {
if (type == 'token') {
tokenRedemption(proposalId, beneficiary, timestamp);
} else if (type === 'reputation') {
} else if (type == 'reputation') {
reputationRedemption(proposalId, beneficiary, timestamp);
} else {
daoBountyRedemption(proposalId, beneficiary, timestamp);
Expand Down
32 changes: 16 additions & 16 deletions src/domain/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class IPFSData {
}

export function parseOutcome(num: BigInt): string {
if (num.toI32() === 1) {
if (num.toI32() == 1) {
// Yes
return 'Pass';
} else {
Expand Down Expand Up @@ -74,7 +74,7 @@ export function getProposalIPFSData(proposal: Proposal): Proposal {
let tags: string[] = [];
let tagsLength = tagsObjects.length < 100 ? tagsObjects.length : 100;
for (let i = 0; i < tagsLength; i++) {
if (tags.indexOf(tagsObjects[i].toString()) === -1) {
if (tags.indexOf(tagsObjects[i].toString()) == -1) {
tags.push(tagsObjects[i].toString());
let tagEnt = Tag.load(tagsObjects[i].toString());
if (tagEnt == null) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export function getIPFSData(descHash: string): IPFSData {
result.url = descJson.toObject().get('url').toString();
}
let tagsData = descJson.toObject().get('tags');
if (tagsData != null && tagsData.kind === JSONValueKind.ARRAY) {
if (tagsData != null && tagsData.kind == JSONValueKind.ARRAY) {
result.tags = tagsData.toArray();
}
}
Expand All @@ -149,7 +149,7 @@ export function updateProposalAfterVote(
// proposal.winningVote
proposal.winningOutcome = parseOutcome(gpProposal.value3);
if (!equalStrings(proposal.winningOutcome, prevOutcome)) {
if ((gpProposal.value2 === 6)) {
if ((gpProposal.value2 == 6)) {
setProposalState(proposal, 6, gp.getProposalTimes(proposalId));
}
addVoteFlipEvent(proposalId, proposal, voter, timestamp);
Expand All @@ -172,7 +172,7 @@ export function updateProposalState(id: Bytes, state: number, gpAddress: Address
proposal.scheme,
);
setProposalState(proposal, state, gp.getProposalTimes(id));
if (state === 4) {
if (state == 4) {
proposal.confidenceThreshold = gp.proposals(id).value10;
}
saveProposal(proposal);
Expand Down Expand Up @@ -205,7 +205,7 @@ export function setProposalState(proposal: Proposal, state: number, gpTimes: Big
dao.numberOfBoostedProposals = dao.numberOfBoostedProposals.minus(BigInt.fromI32(1));
}
}
if (state === 1) {
if (state == 1) {
// Closed
proposal.stage = 'ExpiredInQueue';
if (controllerScheme != null) {
Expand All @@ -216,10 +216,10 @@ export function setProposalState(proposal: Proposal, state: number, gpTimes: Big
dao.numberOfExpiredInQueueProposals = dao.numberOfExpiredInQueueProposals.plus(BigInt.fromI32(1));
}
proposal.accountsWithUnclaimedRewards = new Array<Bytes>();
} else if (state === 2) {
} else if (state == 2) {
// Executed
proposal.stage = 'Executed';
} else if (state === 3) {
} else if (state == 3) {
// Queued
proposal.stage = 'Queued';
proposal.closingAt = proposal.createdAt +
Expand All @@ -231,7 +231,7 @@ export function setProposalState(proposal: Proposal, state: number, gpTimes: Big
if (dao != null) {
dao.numberOfQueuedProposals = dao.numberOfQueuedProposals.plus(BigInt.fromI32(1));
}
} else if (state === 4) {
} else if (state == 4) {
// PreBoosted
proposal.stage = 'PreBoosted';
proposal.preBoostedAt = gpTimes[2];
Expand All @@ -244,7 +244,7 @@ export function setProposalState(proposal: Proposal, state: number, gpTimes: Big
if (dao != null) {
dao.numberOfPreBoostedProposals = dao.numberOfPreBoostedProposals.plus(BigInt.fromI32(1));
}
} else if (state === 5) {
} else if (state == 5) {
// Boosted
proposal.boostedAt = gpTimes[1];
proposal.stage = 'Boosted';
Expand All @@ -257,7 +257,7 @@ export function setProposalState(proposal: Proposal, state: number, gpTimes: Big
if (dao != null) {
dao.numberOfBoostedProposals = dao.numberOfBoostedProposals.plus(BigInt.fromI32(1));
}
} else if (state === 6) {
} else if (state == 6) {
// QuietEndingPeriod
proposal.quietEndingPeriodBeganAt = gpTimes[1];
proposal.closingAt = proposal.quietEndingPeriodBeganAt +
Expand Down Expand Up @@ -404,15 +404,15 @@ export function updateProposalExecution(
export function updateProposalExecutionState(id: string, executionState: number): void {
let proposal = getProposal(id);
// enum ExecutionState { None, QueueBarCrossed, QueueTimeOut, PreBoostedBarCrossed, BoostedTimeOut, BoostedBarCrossed}
if (executionState === 1) {
if (executionState == 1) {
proposal.executionState = 'QueueBarCrossed';
} else if (executionState === 2) {
} else if (executionState == 2) {
proposal.executionState = 'QueueTimeOut';
} else if (executionState === 3) {
} else if (executionState == 3) {
proposal.executionState = 'PreBoostedBarCrossed';
} else if (executionState === 4) {
} else if (executionState == 4) {
proposal.executionState = 'BoostedTimeOut';
} else if (executionState === 5) {
} else if (executionState == 5) {
proposal.executionState = 'BoostedBarCrossed';
}
saveProposal(proposal);
Expand Down
32 changes: 16 additions & 16 deletions src/domain/reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function insertGPRewardsToHelper(proposalId: Bytes, beneficiary: Address)
break;
}
}
if (i === gpRewards.length) { // not exist
if (i == gpRewards.length) { // not exist
updatePreGPReward(rewardId, beneficiary);
gpRewards.push(rewardId);
gpRewardsHelper.gpRewards = gpRewards;
Expand Down Expand Up @@ -96,13 +96,13 @@ export function shouldRemoveAccountFromUnclaimed(reward: GPReward): boolean {
}

return ((reward.reputationForVoter == null ||
reward.reputationForVoterRedeemedAt.isZero() === false) &&
reward.reputationForVoterRedeemedAt.isZero() == false) &&
(reward.reputationForProposer == null ||
reward.reputationForProposerRedeemedAt.isZero() === false) &&
reward.reputationForProposerRedeemedAt.isZero() == false) &&
(reward.tokensForStaker == null ||
reward.tokensForStakerRedeemedAt.isZero() === false) &&
reward.tokensForStakerRedeemedAt.isZero() == false) &&
(reward.daoBountyForStaker == null ||
reward.daoBountyForStakerRedeemedAt.isZero() === false)
reward.daoBountyForStakerRedeemedAt.isZero() == false)
);
}

Expand All @@ -122,16 +122,16 @@ export function shouldRemoveContributorFromUnclaimed(proposal: ContributionRewar
return (
(proposal.reputationReward.isZero() ||
(proposal.alreadyRedeemedReputationPeriods !== null &&
BigInt.compare(proposal.alreadyRedeemedReputationPeriods as BigInt, proposal.periods) === 0)) &&
BigInt.compare(proposal.alreadyRedeemedReputationPeriods as BigInt, proposal.periods) == 0)) &&
(proposal.nativeTokenReward.isZero() ||
(proposal.alreadyRedeemedNativeTokenPeriods !== null &&
BigInt.compare(proposal.alreadyRedeemedNativeTokenPeriods as BigInt, proposal.periods) === 0)) &&
BigInt.compare(proposal.alreadyRedeemedNativeTokenPeriods as BigInt, proposal.periods) == 0)) &&
(proposal.externalTokenReward.isZero() ||
(proposal.alreadyRedeemedExternalTokenPeriods !== null &&
BigInt.compare(proposal.alreadyRedeemedExternalTokenPeriods as BigInt, proposal.periods) === 0)) &&
BigInt.compare(proposal.alreadyRedeemedExternalTokenPeriods as BigInt, proposal.periods) == 0)) &&
(proposal.ethReward.isZero() ||
(proposal.alreadyRedeemedEthPeriods !== null &&
BigInt.compare(proposal.alreadyRedeemedEthPeriods as BigInt, proposal.periods) === 0)));
BigInt.compare(proposal.alreadyRedeemedEthPeriods as BigInt, proposal.periods) == 0)));
}

export function insertGPRewards(
Expand All @@ -151,7 +151,7 @@ export function insertGPRewards(
}
for (i = 0; i < gpRewards.length; i++) {
let gpReward = PreGPReward.load(gpRewards[i]);
if (gpReward === null) { continue; }
if (gpReward == null) { continue; }
let redeemValues: BigInt[];
redeemValues[0] = BigInt.fromI32(0);
redeemValues[1] = BigInt.fromI32(0);
Expand All @@ -165,7 +165,7 @@ export function insertGPRewards(
} else {
redeemValues = callResult.value;
}
if (state === 2) {// call redeemDaoBounty only on execute
if (state == 2) {// call redeemDaoBounty only on execute
let callResultRedeemDaoBounty =
genesisProtocol.try_redeemDaoBounty(proposalId, gpReward.beneficiary as Address);
if (callResultRedeemDaoBounty.reverted) {
Expand Down Expand Up @@ -198,7 +198,7 @@ export function insertGPRewards(
break;
}
}
if (idx === accountsWithUnclaimedRewards.length) {
if (idx == accountsWithUnclaimedRewards.length) {
addRedeemableRewardOwner(proposal, gpReward.beneficiary);
}
} else {
Expand Down Expand Up @@ -233,16 +233,16 @@ function updateGPReward(id: string,
reward.reputationForProposerRedeemedAt = BigInt.fromI32(0);
reward.daoBountyForStakerRedeemedAt = BigInt.fromI32(0);
}
if (reputationForVoter.isZero() === false) {
if (reputationForVoter.isZero() == false) {
reward.reputationForVoter = reputationForVoter;
}
if (tokensForStaker.isZero() === false) {
if (tokensForStaker.isZero() == false) {
reward.tokensForStaker = tokensForStaker;
}
if (reputationForProposer.isZero() === false) {
if (reputationForProposer.isZero() == false) {
reward.reputationForProposer = reputationForProposer;
}
if (daoBountyForStaker.isZero() === false) {
if (daoBountyForStaker.isZero() == false) {
reward.daoBountyForStaker = daoBountyForStaker;
let genesisProtocol = GenesisProtocol.bind(gpAddress as Address);
reward.tokenAddress = genesisProtocol.stakingToken();
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/Competition/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function getSuggestionIPFSData(suggestion: CompetitionSuggestion): Compet
let tags: string[] = [];
let tagsLength = tagsObjects.length < 100 ? tagsObjects.length : 100;
for (let i = 0; i < tagsLength; i++) {
if (tags.indexOf(tagsObjects[i].toString()) === -1) {
if (tags.indexOf(tagsObjects[i].toString()) == -1) {
tags.push(tagsObjects[i].toString());
let tagEnt = Tag.load(tagsObjects[i].toString());
if (tagEnt == null) {
Expand Down
12 changes: 6 additions & 6 deletions src/mappings/ContributionReward/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,25 @@ function updateProposalAfterRedemption(
) as ContributionRewardProposal;
if (ent != null) {
let cr = ContributionReward.bind(contributionRewardAddress);
if (type === 0) {
if (type == 0) {
ent.alreadyRedeemedReputationPeriods = cr.getRedeemedPeriods(
proposalId,
ent.avatar as Address,
BigInt.fromI32(0),
);
} else if (type === 1) {
} else if (type == 1) {
ent.alreadyRedeemedNativeTokenPeriods = cr.getRedeemedPeriods(
proposalId,
ent.avatar as Address,
BigInt.fromI32(1),
);
} else if (type === 2) {
} else if (type == 2) {
ent.alreadyRedeemedEthPeriods = cr.getRedeemedPeriods(
proposalId,
ent.avatar as Address,
BigInt.fromI32(2),
);
} else if (type === 3) {
} else if (type == 3) {
ent.alreadyRedeemedExternalTokenPeriods = cr.getRedeemedPeriods(
proposalId,
ent.avatar as Address,
Expand All @@ -138,7 +138,7 @@ function updateProposalAfterRedemption(
store.set('ContributionRewardProposal', proposalId.toHex(), ent);
let reward = GPReward.load(crypto.keccak256(concat(proposalId, ent.beneficiary)).toHex());
if ((reward !== null && shouldRemoveAccountFromUnclaimed(reward as GPReward)) ||
(reward === null && shouldRemoveContributorFromUnclaimed(ent))) {
(reward == null && shouldRemoveContributorFromUnclaimed(ent))) {
removeRedeemableRewardOwner(proposalId, ent.beneficiary);
}
}
Expand All @@ -161,7 +161,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
ent.txHash = event.transaction.hash;
ent.contract = event.address;
ent.avatar = event.params._avatar;
ent.passed = (event.params._param.toI32() === 1);
ent.passed = (event.params._param.toI32() == 1);
ent.proposalId = event.params._proposalId;
store.set('ContributionRewardProposalResolved', ent.id, ent);
}
Expand Down
14 changes: 7 additions & 7 deletions src/mappings/ContributionRewardExt/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ function updateProposalAfterRedemption(
if (ent != null) {
let cr = ContributionRewardExt.bind(contributionRewardAddress);
let proposal = cr.organizationProposals(proposalId);
if (type === 0) {
if (type == 0) {
if (proposal.value1.isZero()) {
ent.alreadyRedeemedReputationPeriods = BigInt.fromI32(1);
}
ent.reputationChangeLeft = proposal.value7;
} else if (type === 1) {
} else if (type == 1) {
if (proposal.value0.isZero()) {
ent.alreadyRedeemedNativeTokenPeriods = BigInt.fromI32(1);
}
ent.nativeTokenRewardLeft = proposal.value6;
} else if (type === 2) {
} else if (type == 2) {
if (proposal.value2.isZero()) {
ent.alreadyRedeemedEthPeriods = BigInt.fromI32(1);
}
ent.ethRewardLeft = proposal.value8;
} else if (type === 3) {
} else if (type == 3) {
if (proposal.value4.isZero()) {
ent.alreadyRedeemedExternalTokenPeriods = BigInt.fromI32(1);
}
Expand All @@ -132,7 +132,7 @@ function updateProposalAfterRedemption(
store.set('ContributionRewardProposal', proposalId.toHex(), ent);
let reward = GPReward.load(crypto.keccak256(concat(proposalId, ent.beneficiary)).toHex());
if ((reward !== null && shouldRemoveAccountFromUnclaimed(reward as GPReward)) ||
(reward === null && shouldRemoveContributorFromUnclaimed(ent))) {
(reward == null && shouldRemoveContributorFromUnclaimed(ent))) {
removeRedeemableRewardOwner(proposalId, ent.beneficiary);
}
}
Expand All @@ -146,7 +146,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
) as ContributionRewardProposal;
if (proposalEnt != null) {
proposalEnt.executedAt = event.block.timestamp;
if (event.params._param.toI32() === 1) {
if (event.params._param.toI32() == 1) {
proposalEnt.reputationChangeLeft = proposalEnt.reputationReward;
proposalEnt.nativeTokenRewardLeft = proposalEnt.nativeTokenReward;
proposalEnt.ethRewardLeft = proposalEnt.ethReward;
Expand All @@ -159,7 +159,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
ent.txHash = event.transaction.hash;
ent.contract = event.address;
ent.avatar = event.params._avatar;
ent.passed = (event.params._param.toI32() === 1);
ent.passed = (event.params._param.toI32() == 1);
ent.proposalId = event.params._proposalId;
store.set('ContributionRewardProposalResolved', ent.id, ent);
}
Expand Down
Loading