Skip to content

Commit

Permalink
Merge pull request #1348 from decent-dao/fix/quorum-multiplication
Browse files Browse the repository at this point in the history
Fix quorum formatting
  • Loading branch information
mudrila authored Feb 9, 2024
2 parents e4166d5 + 82e1662 commit 8aba272
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
17 changes: 10 additions & 7 deletions src/hooks/DAO/loaders/governance/useERC20LinearStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ export const useERC20LinearStrategy = () => {
if (!ozLinearVotingContract || !azoriusContract) {
return {};
}
const [votingPeriodBlocks, quorumNumerator, timeLockPeriod] = await Promise.all([
ozLinearVotingContract.asSigner.votingPeriod(),
ozLinearVotingContract.asSigner.quorumNumerator(),
azoriusContract.asSigner.timelockPeriod(),
]);
const [votingPeriodBlocks, quorumNumerator, quorumDenominator, timeLockPeriod] =
await Promise.all([
ozLinearVotingContract.asSigner.votingPeriod(),
ozLinearVotingContract.asSigner.quorumNumerator(),
ozLinearVotingContract.asSigner.QUORUM_DENOMINATOR(),
azoriusContract.asSigner.timelockPeriod(),
]);

const quorumPercentage = quorumNumerator.mul(100).div(quorumDenominator);
const votingPeriodValue = await blocksToSeconds(votingPeriodBlocks, provider);
const timeLockPeriodValue = await blocksToSeconds(timeLockPeriod, provider);
const votingData = {
Expand All @@ -42,8 +45,8 @@ export const useERC20LinearStrategy = () => {
formatted: getTimeDuration(votingPeriodValue),
},
quorumPercentage: {
value: quorumNumerator,
formatted: quorumNumerator.toString() + '%',
value: quorumPercentage,
formatted: quorumPercentage.toString() + '%',
},
timeLockPeriod: {
value: BigNumber.from(timeLockPeriodValue),
Expand Down
23 changes: 15 additions & 8 deletions src/models/AzoriusTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,22 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
}
}
}
}

this.setPredictedStrategyAddress();
public async init() {
await this.setPredictedStrategyAddress();
this.setPredictedAzoriusAddress();
this.setContracts();

if (daoData.votingStrategyType === VotingStrategyType.LINEAR_ERC20) {
daoData = daoData as AzoriusERC20DAO;
if (
(this.daoData as AzoriusERC20DAO | AzoriusERC721DAO).votingStrategyType ===
VotingStrategyType.LINEAR_ERC20
) {
const azoriusDAOData = this.daoData as AzoriusERC20DAO;
if (
parentTokenAddress &&
daoData.parentAllocationAmount &&
!daoData.parentAllocationAmount.isZero()
this.parentTokenAddress &&
azoriusDAOData.parentAllocationAmount &&
!azoriusDAOData.parentAllocationAmount.isZero()
) {
this.setEncodedSetupTokenClaimData();
this.setPredictedTokenClaimAddress();
Expand Down Expand Up @@ -373,9 +378,11 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
);
}

private setPredictedStrategyAddress() {
private async setPredictedStrategyAddress() {
const azoriusGovernanceDaoData = this.daoData as AzoriusGovernanceDAO;
if (azoriusGovernanceDaoData.votingStrategyType === VotingStrategyType.LINEAR_ERC20) {
const quorumDenominator =
await this.azoriusContracts!.linearVotingMasterCopyContract.QUORUM_DENOMINATOR();
const encodedStrategyInitParams = defaultAbiCoder.encode(
['address', 'address', 'address', 'uint32', 'uint256', 'uint256', 'uint256'],
[
Expand All @@ -384,7 +391,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
'0x0000000000000000000000000000000000000001', // Azorius module
azoriusGovernanceDaoData.votingPeriod,
BigNumber.from(1), // proposer weight, how much is needed to create a proposal.
azoriusGovernanceDaoData.quorumPercentage, // quorom numerator, denominator is 1,000,000, so quorum percentage is 50%
azoriusGovernanceDaoData.quorumPercentage.mul(quorumDenominator.div(100)), // quorom numerator, denominator is 1,000,000, so quorum percentage is quorumNumerator * 100 / quorumDenominator
BigNumber.from(500000), // basis numerator, denominator is 1,000,000, so basis percentage is 50% (simple majority)
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
shouldSetSnapshot: boolean = true,
existingSafe?: { owners: string[] }
): Promise<string> {
const azoriusTxBuilder = this.txBuilderFactory.createAzoriusTxBuilder();
const azoriusTxBuilder = await this.txBuilderFactory.createAzoriusTxBuilder();

// transactions that must be called by safe
this.internalTxs = [];
Expand Down
7 changes: 5 additions & 2 deletions src/models/TxBuilderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export class TxBuilderFactory extends BaseTxBuilder {
);
}

public createAzoriusTxBuilder(): AzoriusTxBuilder {
return new AzoriusTxBuilder(
public async createAzoriusTxBuilder(): Promise<AzoriusTxBuilder> {
const azoriusTxBuilder = new AzoriusTxBuilder(
this.signerOrProvider,
this.baseContracts,
this.azoriusContracts!,
Expand All @@ -129,5 +129,8 @@ export class TxBuilderFactory extends BaseTxBuilder {
this.parentAddress,
this.parentTokenAddress
);

await azoriusTxBuilder.init();
return azoriusTxBuilder;
}
}

0 comments on commit 8aba272

Please sign in to comment.