Skip to content

Commit

Permalink
Merge pull request #2912 from IntersectMBO/feat/2258-propose-new-cons…
Browse files Browse the repository at this point in the history
…titution-or-guardrails-script-governance-action-for-an-offchain-discussion-and-submit-it-as-a-governance-action

feat(#2258): add support for submitting all governance action types
  • Loading branch information
MSzalowski authored Feb 11, 2025
2 parents deb388b + 1019178 commit 88813eb
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ changes.

- Add metadata url and hash to drep details [Issue 2911](https://github.com/IntersectMBO/govtool/issues/2911)
- Add CC votes percentages, not voted and Ratification threshold
- Add support for submitting all 7 governance action types [Issue 2258](https://github.com/IntersectMBO/govtool/issues/2258)

### Fixed

Expand Down
113 changes: 85 additions & 28 deletions docs/GOVERNANCE_ACTION_SUBMISSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ interface GovernanceAction {
references: [{ label: string; uri: string }];
}

interface InfoProps {
hash: string;
type VotingAnchor = {
url: string;
hash: string;
}

interface TreasuryProps {
amount: string;
hash: string;
type InfoProps = VotingAnchor;

type TreasuryProps {
withdrawals: { receivingAddress: string; amount: string }[];
}
} & VotingAnchor;

type ProtocolParamsUpdate = {
adaPerUtxo: string;
Expand Down Expand Up @@ -77,14 +77,44 @@ type ProtocolParamsUpdate = {
treasuryGrowthRate: UnitInterval;
};

interface ProtocolParameterChangeProps {
type ProtocolParameterChangeProps {
prevGovernanceActionHash: string;
prevGovernanceActionIndex: number;
url: string;
hash: string;

protocolParamsUpdate: Partial<ProtocolParamsUpdate>;
}
} & VotingAnchor;

type HardForkInitiationProps = {
prevGovernanceActionHash: string;
prevGovernanceActionIndex: number;
major: number;
minor: number;
} & VotingAnchor;

type NewConstitutionProps = {
prevGovernanceActionHash: string;
prevGovernanceActionIndex: number;
constitutionUrl: string;
constitutionHash: string;
scriptHash: string;
} & VotingAnchor;

type UpdateCommitteeProps = {
prevGovernanceActionHash?: string;
prevGovernanceActionIndex?: number;
quorumThreshold: QuorumThreshold;
newCommittee?: CommitteeToAdd[];
removeCommittee?: string[];
} & VotingAnchor;

type CommitteeToAdd = {
expiryEpoch: number;
committee: string;
};

type QuorumThreshold = {
numerator: number;
denominator: number;
};

const createGovernanceActionJsonLD: (
governanceAction: GovernanceAction
Expand All @@ -100,6 +130,22 @@ const buildTreasuryGovernanceAction: (
treasuryProps: TreasuryProps
) => Promise<VotingProposalBuilder | undefined>;

const buildProtocolParameterChangeGovernanceAction: (
protocolParameterChangeProps: ProtocolParameterChangeProps
) => Promise<VotingProposalBuilder | undefined>;

const buildHardForkInitiationGovernanceAction: (
hardForkInitiationProps: HardForkInitiationProps
) => Promise<VotingProposalBuilder | undefined>;

const buildNewConstitutionGovernanceAction: (
newConstitutionProps: NewConstitutionProps
) => Promise<VotingProposalBuilder | undefined>;

const buildUpdateCommitteeGovernanceAction: (
updateCommitteeProps: UpdateCommitteeProps
) => Promise<VotingProposalBuilder | undefined>;

const buildSignSubmitConwayCertTx: (params: {
govActionBuilder: VotingProposalBuilder;
type: "createGovAction";
Expand Down Expand Up @@ -165,44 +211,37 @@ const {
buildNewInfoGovernanceAction,
buildProtocolParameterChangeGovernanceAction,
buildHardForkInitiationGovernanceAction,
buildTreasuryGovernanceAction,
buildNewConstitutionGovernanceAction,
buildUpdateCommitteeGovernanceAction,
buildNoConfidenceGovernanceAction,
} = useCardano();

// Info Governance Action
const govActionBuilder = await buildNewInfoGovernanceAction({ hash, url });
let govActionBuilder = await buildNewInfoGovernanceAction({ hash, url });

// sign and submit the transaction
await buildSignSubmitConwayCertTx({
govActionBuilder,
type: "createGovAction",
});
// And for the other type of governance actions:

// Treasury Governance Action
const { buildTreasuryGovernanceAction } = useCardano();
govActionBuilder = await buildNoConfidenceGovernanceAction({ hash, url });

// hash of the generated Governance Action metadata, url of the metadata, amount of the transaction, receiving address is the stake key address
const govActionBuilder = await buildTreasuryGovernanceAction({
govActionBuilder = await buildTreasuryGovernanceAction({
hash,
url,
withdrawals: [{ amount, receivingAddress }],
});

// Protocol Parameter Change Governance Action
const { buildProtocolParameterChangeGovernanceAction } = useCardano();

// hash of the previous Governance Action, index of the previous Governance Action, url of the metadata, hash of the metadata, and the updated protocol parameters
const govActionBuilder = await buildProtocolParameterChangeGovernanceAction({
govActionBuilder = await buildProtocolParameterChangeGovernanceAction({
prevGovernanceActionHash,
prevGovernanceActionIndex,
url,
hash,
protocolParamsUpdate,
});

// Hard Fork Initiation Governance Action
const { buildHardForkInitiationGovernanceAction } = useCardano();

// hash of the previous Governance Action, index of the previous Governance Action, url of the metadata, hash of the metadata, and the major and minor numbers of the hard fork initiation
const govActionBuilder = await buildHardForkInitiationGovernanceAction({
govActionBuilder = await buildHardForkInitiationGovernanceAction({
prevGovernanceActionHash,
prevGovernanceActionIndex,
url,
Expand All @@ -211,6 +250,24 @@ const govActionBuilder = await buildHardForkInitiationGovernanceAction({
minor,
});

// hash of the previous Governance Action, index of the previous Governance Action, url of the metadata, hash of the metadata, and the constitution script hash
govActionBuilder = await buildNewConstitutionGovernanceAction({
prevGovernanceActionHash,
prevGovernanceActionIndex,
constitutionUrl,
constitutionHash,
scriptHash,
});

// hash of the previous Governance Action, index of the previous Governance Action, url of the metadata, hash of the metadata, and the quorum threshold and the new committee members
govActionBuilder = await buildUpdateCommitteeGovernanceAction({
prevGovernanceActionHash,
prevGovernanceActionIndex,
quorumThreshold,
newCommittee,
removeCommittee,
});

// sign and submit the transaction
await buildSignSubmitConwayCertTx({
govActionBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const CreateGovernanceActionForm = ({
type! as
| GovernanceActionType.InfoAction
| GovernanceActionType.TreasuryWithdrawals
| GovernanceActionType.NewCommittee
| GovernanceActionType.NewConstitution
| GovernanceActionType.NoConfidence
],
).some(
(field) => !watch(field as unknown as Parameters<typeof watch>[0]),
Expand All @@ -67,6 +70,9 @@ export const CreateGovernanceActionForm = ({
type! as
| GovernanceActionType.InfoAction
| GovernanceActionType.TreasuryWithdrawals
| GovernanceActionType.NewCommittee
| GovernanceActionType.NewConstitution
| GovernanceActionType.NoConfidence
],
).map(([key, field]) => {
const fieldProps = {
Expand Down
139 changes: 139 additions & 0 deletions govtool/frontend/src/consts/governanceAction/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,92 @@ export const sharedGovernanceActionFields: SharedGovernanceActionFieldSchema = {

export const GOVERNANCE_ACTION_FIELDS: GovernanceActionFields = {
[GovernanceActionType.InfoAction]: sharedGovernanceActionFields,
[GovernanceActionType.NoConfidence]: sharedGovernanceActionFields,
[GovernanceActionType.NewCommittee]: {
...sharedGovernanceActionFields,
numerator: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.numerator.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.numerator.placeholder",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
validate: numberValidation,
},
},
denominator: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.denominator.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.denominator.placeholder",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
validate: numberValidation,
},
},
newCommitteeHash: {
component: GovernanceActionField.Input,
labelI18nKey: "createGovernanceAction.fields.declarations.members.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.members.placeholder",
tipI18nKey: "createGovernanceAction.fields.declarations.members.tip",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
maxLength: {
value: 500,
message: I18n.t(
"createGovernanceAction.fields.validations.maxLength",
{
maxLength: 500,
},
),
},
},
},
newCommitteeExpiryEpoch: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.expiryEpoch.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.expiryEpoch.placeholder",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
validate: numberValidation,
},
},
removeCommitteeHash: {
component: GovernanceActionField.Input,
labelI18nKey: "createGovernanceAction.fields.declarations.remove.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.remove.placeholder",
tipI18nKey: "createGovernanceAction.fields.declarations.remove.tip",
rules: {
maxLength: {
value: 500,
message: I18n.t(
"createGovernanceAction.fields.validations.maxLength",
{
maxLength: 500,
},
),
},
},
},
},
[GovernanceActionType.TreasuryWithdrawals]: {
...sharedGovernanceActionFields,
receivingAddress: {
Expand All @@ -123,6 +209,59 @@ export const GOVERNANCE_ACTION_FIELDS: GovernanceActionFields = {
},
},
},
[GovernanceActionType.NewConstitution]: {
...sharedGovernanceActionFields,
prevGovernanceActionHash: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.prevGovernanceActionHash.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.prevGovernanceActionHash.placeholder",
},
prevGovernanceActionIndex: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.prevGovernanceActionIndex.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.prevGovernanceActionIndex.placeholder",
rules: {
validate: numberValidation,
},
},
constitutionUrl: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.constitutionUrl.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.constitutionUrl.placeholder",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
},
},
constitutionHash: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.constitutionHash.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.constitutionHash.placeholder",
rules: {
required: {
value: true,
message: I18n.t("createGovernanceAction.fields.validations.required"),
},
},
},
scriptHash: {
component: GovernanceActionField.Input,
labelI18nKey:
"createGovernanceAction.fields.declarations.scriptHash.label",
placeholderI18nKey:
"createGovernanceAction.fields.declarations.scriptHash.placeholder",
},
},
} as const;

export const GOVERNANCE_ACTION_CONTEXT = {
Expand Down
Loading

0 comments on commit 88813eb

Please sign in to comment.