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

Fix quorum formatting #1348

Merged
merged 6 commits into from
Feb 9, 2024
Merged
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

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;
Comment on lines +101 to +104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mudrila can you explain these few lines a bit more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the parentAllocationAmount exists only for AzoriusERC20DAO, only then we need to call setEncodedSetupTokenClaimData and setPredictedTokenClaimAddress - this const azoriusDAOData = this.daoData as AzoriusERC20DAO; performed solely for type constraints.
This is mostly copy-paste of lines removed from constructor but before it was daoData = daoData as AzoriusERC20DAO and we just don't need (and actually can't ahah) to reassign to this.daoData

And if you're talking about async init - that's to fetch QUORUM_DENOMINATOR on chain, we need to await for RPC request promise.

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;
}
}
Loading