Skip to content

Commit

Permalink
CustomProposalSubmitter for Shutter DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Mar 26, 2024
1 parent a528779 commit c960d38
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Button } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { DAO_ROUTES } from '../../../../../constants/routes';
import useSubmitProposal from '../../../../../hooks/DAO/proposal/useSubmitProposal';
import { ProposalExecuteData } from '../../../../../types';
import { encodeProposalTransaction } from '../../../../../utils';

export default function CustomProposalSubmitter({
values,
daoAddress,
}: {
values: any;
daoAddress?: string;
}) {
const { submitProposal } = useSubmitProposal();
const navigate = useNavigate();
const { t } = useTranslation(['proposal', 'common', 'breadcrumbs']);

const successCallback = () => {
if (daoAddress) {
navigate(DAO_ROUTES.proposals.relative(daoAddress));
}
};
const handleSubmitProposal = () => {
const target = '0x7CC7e125d83A581ff438608490Cc0f7bDff79127'; // SablierV2LockupDynamic
const functionName = 'createWithMilestones';
const signature =
'function createWithMilestones(address,address,(address,uint40,bool,bool,address,uint128,(address,uint256),(uint128,uint64,uint40)[])[])';
const data = [
'0x7CC7e125d83A581ff438608490Cc0f7bDff79127',
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
[
[
'0x36bD3044ab68f600f6d3e081056F34f2a58432c4',
1711980240,
true,
false,
'0x36bD3044ab68f600f6d3e081056F34f2a58432c4',
25000000000,
['0x0000000000000000000000000000000000000000', 0],
[
[0, '1000000000000000000', 1714572239],
[5000000000, '1000000000000000000', 1714572240],
[0, '1000000000000000000', 1717250639],
[5000000000, '1000000000000000000', 1717250640],
[0, '1000000000000000000', 1719842639],
[5000000000, '1000000000000000000', 1719842640],
[0, '1000000000000000000', 1722521039],
[5000000000, '1000000000000000000', 1722521040],
[0, '1000000000000000000', 1725199439],
[5000000000, '1000000000000000000', 1725199440],
],
],
],
];

const { nonce, proposalMetadata } = values;
const calldata = encodeProposalTransaction(functionName, signature, data);
const proposalData: ProposalExecuteData = {
targets: [target],
values: [0],
calldatas: [calldata],
metaData: {
title: proposalMetadata.title,
description: proposalMetadata.description,
documentationUrl: proposalMetadata.documentationUrl,
},
};
submitProposal({
proposalData,
nonce,
pendingToastMessage: t('proposalCreatePendingToastMessage'),
successToastMessage: t('proposalCreateSuccessToastMessage'),
failedToastMessage: t('proposalCreateFailureToastMessage'),
successCallback,
});
};
return <Button onClick={handleSubmitProposal}>Submit custom Shutter DAO proposal</Button>;
}
4 changes: 4 additions & 0 deletions src/pages/daos/[daoAddress]/proposals/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import useSubmitProposal from '../../../../../hooks/DAO/proposal/useSubmitPropos
import { useCreateProposalSchema } from '../../../../../hooks/schemas/proposalCreate/useCreateProposalSchema';
import { useFractal } from '../../../../../providers/App/AppProvider';
import { CreateProposalForm, CreateProposalState, GovernanceType } from '../../../../../types';
import CustomProposalSubmitter from './CustomProposalSubmitter';

const templateAreaTwoCol = '"content details"';
const templateAreaSingleCol = `"content"
"details"`;

const SHUTTER_DAO_ADDRESS = '0x1CEB4eB34A0AA9D439Dd0A4bab0f6830f715ddF0';

export default function ProposalCreatePage() {
const {
node: { daoAddress, safe },
Expand Down Expand Up @@ -96,6 +99,7 @@ export default function ProposalCreatePage() {
buttonClick={() => navigate(DAO_ROUTES.proposals.relative(daoAddress))}
isButtonDisabled={pendingCreateTx}
/>
{daoAddress === SHUTTER_DAO_ADDRESS && <CustomProposalSubmitter values={values} />}
<Grid
gap={4}
templateColumns={{ base: '1fr', lg: '2fr 1fr' }}
Expand Down
1 change: 0 additions & 1 deletion src/utils/azorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const getProposalVotes = async (
...rest,
voter,
choice: VOTE_CHOICES[voteType],
weight: rest.weight!,
} as ProposalVote; // This bypasses the type check, but it's fine
});
};
Expand Down
49 changes: 1 addition & 48 deletions src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,60 +95,13 @@ export const encodeFunction = (
};

export const encodeProposalTransaction = (
target: string,
functionName: string,
signature: string,
data: any,
metaData: { title: string; description: string; documentationUrl?: string },
) => {
const calldata = new utils.Interface([signature]).encodeFunctionData(functionName, data);
const stringifiedMetadata = JSON.stringify(metaData);
return {
transaction: { to: target, value: 0, data: calldata, operation: 0 },
metaData: stringifiedMetadata,
};
return new utils.Interface([signature]).encodeFunctionData(functionName, data);
};

const target = '0x7CC7e125d83A581ff438608490Cc0f7bDff79127'; // SablierV2LockupDynamic
const functionName = 'createWithMilestones';
const signature =
'function createWithMilestones(address,address,(address,uint40,bool,bool,address,uint128,(address,uint256),(uint128,uint64,uint40)[])[])';
const data = [
'0x7CC7e125d83A581ff438608490Cc0f7bDff79127',
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
[
[
'0x36bD3044ab68f600f6d3e081056F34f2a58432c4',
1711980240,
true,
false,
'0x36bD3044ab68f600f6d3e081056F34f2a58432c4',
25000000000,
['0x0000000000000000000000000000000000000000', 0],
[
[0, '1000000000000000000', 1714572239],
[5000000000, '1000000000000000000', 1714572240],
[0, '1000000000000000000', 1717250639],
[5000000000, '1000000000000000000', 1717250640],
[0, '1000000000000000000', 1719842639],
[5000000000, '1000000000000000000', 1719842640],
[0, '1000000000000000000', 1722521039],
[5000000000, '1000000000000000000', 1722521040],
[0, '1000000000000000000', 1725199439],
[5000000000, '1000000000000000000', 1725199440],
],
],
],
];

const metaData = {
title: 'Sablier proposal',
description: 'Sablier proposal description. Markdown supported!',
documentationUrl: '',
};

console.log(encodeProposalTransaction(target, functionName, signature, data, metaData));

export function isMultiSigTx(transaction: ActivityTransactionType): boolean {
return transaction.txType === 'MULTISIG_TRANSACTION';
}
Expand Down

0 comments on commit c960d38

Please sign in to comment.