Skip to content

Commit

Permalink
Feat/spell address hash (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinskipg authored Oct 14, 2021
1 parent cdc3e8e commit 6541e2b
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 21 deletions.
32 changes: 32 additions & 0 deletions lib/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export default {
chevron_right: icons.chevron_right,
chevron_left: icons.chevron_left,
chevron_down: icons.chevron_down,
chevron_up: icons.chevron_up,
checkmark: icons.checkmark,
edit: icons.edit,
verified: icons.verified,
Expand Down Expand Up @@ -998,6 +999,37 @@ export default {
fill="currentColor"
/>
)
},
hourglass: {
viewBox: '0 0 14 18',
path: (
<g>
<path
d="M12.6667 1.66667H1.33333C1.14933 1.66667 1 1.51733 1 1.33333C1 1.14933 1.14933 1 1.33333 1H12.6667C12.8507 1 13 1.14933 13 1.33333C13 1.51733 12.8507 1.66667 12.6667 1.66667Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="0.2"
/>
<path
d="M2.66536 17C2.48136 17 2.33203 16.8507 2.33203 16.6667V13.1873C2.33203 12.3387 2.69403 11.526 3.3247 10.9573L4.6747 9.74333C4.88803 9.55133 5.00603 9.28733 5.00603 9C5.00603 8.71267 4.88803 8.44867 4.6747 8.25667L3.32536 7.042C2.69403 6.474 2.33203 5.66133 2.33203 4.81267V1.33333C2.33203 1.14933 2.48136 1 2.66536 1C2.84936 1 2.9987 1.14933 2.9987 1.33333V4.81267C2.9987 5.47267 3.28003 6.10467 3.77136 6.54733L5.12003 7.76133C5.4707 8.07733 5.67203 8.52867 5.67203 9C5.67203 9.47133 5.4707 9.92333 5.1207 10.2387L3.7707 11.4533C3.28003 11.8953 2.9987 12.5273 2.9987 13.1873V16.6667C2.9987 16.8507 2.84936 17 2.66536 17Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="0.2"
/>
<path
d="M11.3348 17C11.1508 17 11.0015 16.8507 11.0015 16.6667V13.1873C11.0015 12.5273 10.7201 11.8953 10.2288 11.4527L8.88012 10.2387C8.52946 9.92267 8.32812 9.47133 8.32812 9C8.32812 8.52867 8.52946 8.07667 8.87946 7.76133L10.2295 6.54733C10.7201 6.10467 11.0015 5.47267 11.0015 4.81267V1.33333C11.0015 1.14933 11.1508 1 11.3348 1C11.5188 1 11.6681 1.14933 11.6681 1.33333V4.81267C11.6681 5.66133 11.3061 6.474 10.6755 7.04267L9.32546 8.25667C9.11279 8.44933 8.99479 8.71333 8.99479 9C8.99479 9.28667 9.11279 9.55133 9.32613 9.74333L10.6748 10.9573C11.3061 11.526 11.6681 12.338 11.6681 13.1873V16.6667C11.6681 16.8507 11.5188 17 11.3348 17Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="0.2"
/>
<path
d="M12.6667 17.0007H1.33333C1.14933 17.0007 1 16.8513 1 16.6673C1 16.4833 1.14933 16.334 1.33333 16.334H12.6667C12.8507 16.334 13 16.4833 13 16.6673C13 16.8513 12.8507 17.0007 12.6667 17.0007Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="0.2"
/>
</g>
)
}
}
};
1 change: 1 addition & 0 deletions modules/executive/api/fetchExecutives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function getExecutiveProposals(network?: SupportedNetworks): Promis

return parseExecutive(proposalDoc, proposalIndex, proposalLink, currentNetwork);
} catch (e) {
console.log(e);
// Catch error and return null if failed fetching one proposal
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/executive/api/mocks/proposals.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"verified": false,
"address": "0x261086981FC6c57EF4679Af6aC253C3755850362",
"proposalLink": "https://github.com",
"about": "# [Executive Vote] Raise the ETH Debt Ceiling\r\n\r\nThe Maker Foundation Interim Governance Facilitator has placed an Executive Vote into the voting system, which will enable the community to approve the following alterations to the protocol:\r\n\r\n- [Raise the Dai ETH Debt Ceiling by 20 million to 140 million Dai](https://vote.makerdao.com/polling-proposal/qmsv7qsmqafardbhun2f9s65nge3xf5oe4we3dswzwbtfy)\r\n\r\nThe Executive Vote ([FAQ](https://community-development.makerdao.com/makerdao-mcd-faqs/faqs#governance)) will continue until the number of votes surpass the total in favor of the previous Executive Vote. This is a [continuous approval](https://community-development.makerdao.com/makerdao-mcd-faqs/faqs/governance#what-is-continuous-approval-voting) vote.\r\n\r\n## Review\r\n\r\nThese changes were discussed in the Governance call on Thursday, June 4. Please review the [Video](https://www.youtube.com/playlist?list=PLLzkWCj8ywWNq5-90-Id6VPSsrk4OWVan), [Audio](https://soundcloud.com/makerdao/sets/governance-calls), and the online [discussion](https://forum.makerdao.com/c/governance) to inform your position before voting.\r\n\r\nThe MakerDAO community is moving forward with an Executive Vote to determine whether it will enact the changes established by the previous [Governance Polls](https://vote.makerdao.com/polling).\r\n\r\n## Action\r\n\r\n**Voting for this proposal will place your MKR in support of implementing the changes outlined above.**\r\n\r\n---\r\n\r\n## Resources\r\n\r\nAdditional information about the Governance process can be found in the [Governance Risk Framework: Governing MakerDAO](https://community-development.makerdao.com/governance/governance-risk-framework)\r\n\r\nDemos, help and instructional material for the Governance Dashboard can be found at [Awesome MakerDAO](https://awesome.makerdao.com/#voting).\r\n\r\nTo participate in future Governance calls, please [join us](https://community-development.makerdao.com/governance/governance-and-risk-meetings) every Thursday at 16:00 UTC.\r\n\r\nTo add current and upcoming votes to your calendar, please see the [MakerDAO Public Events Calendar](https://calendar.google.com/calendar/embed?src=makerdao.com_3efhm2ghipksegl009ktniomdk%40group.calendar.google.com&amp;ctz=America%2FLos_Angeles)."
},
{
Expand All @@ -33,6 +34,7 @@
},
"verified": false,
"address": "0x261086981FC6c57EF4679Af6aC253C3755850362",
"proposalLink": "https://github.com",
"about": "# [Executive Vote] Raise the ETH Debt Ceiling\r\n\r\nThe Maker Foundation Interim Governance Facilitator has placed an Executive Vote into the voting system, which will enable the community to approve the following alterations to the protocol:\r\n\r\n- [Raise the Dai ETH Debt Ceiling by 20 million to 140 million Dai](https://vote.makerdao.com/polling-proposal/qmsv7qsmqafardbhun2f9s65nge3xf5oe4we3dswzwbtfy)\r\n\r\nThe Executive Vote ([FAQ](https://community-development.makerdao.com/makerdao-mcd-faqs/faqs#governance)) will continue until the number of votes surpass the total in favor of the previous Executive Vote. This is a [continuous approval](https://community-development.makerdao.com/makerdao-mcd-faqs/faqs/governance#what-is-continuous-approval-voting) vote.\r\n\r\n## Review\r\n\r\nThese changes were discussed in the Governance call on Thursday, June 4. Please review the [Video](https://www.youtube.com/playlist?list=PLLzkWCj8ywWNq5-90-Id6VPSsrk4OWVan), [Audio](https://soundcloud.com/makerdao/sets/governance-calls), and the online [discussion](https://forum.makerdao.com/c/governance) to inform your position before voting.\r\n\r\nThe MakerDAO community is moving forward with an Executive Vote to determine whether it will enact the changes established by the previous [Governance Polls](https://vote.makerdao.com/polling).\r\n\r\n## Action\r\n\r\n**Voting for this proposal will place your MKR in support of implementing the changes outlined above.**\r\n\r\n---\r\n\r\n## Resources\r\n\r\nAdditional information about the Governance process can be found in the [Governance Risk Framework: Governing MakerDAO](https://community-development.makerdao.com/governance/governance-risk-framework)\r\n\r\nDemos, help and instructional material for the Governance Dashboard can be found at [Awesome MakerDAO](https://awesome.makerdao.com/#voting).\r\n\r\nTo participate in future Governance calls, please [join us](https://community-development.makerdao.com/governance/governance-and-risk-meetings) every Thursday at 16:00 UTC.\r\n\r\nTo add current and upcoming votes to your calendar, please see the [MakerDAO Public Events Calendar](https://calendar.google.com/calendar/embed?src=makerdao.com_3efhm2ghipksegl009ktniomdk%40group.calendar.google.com&amp;ctz=America%2FLos_Angeles)."
}
]
3 changes: 2 additions & 1 deletion modules/executive/api/parseExecutive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function parseExecutive(
key: slugify(title),
address: address,
date: String(date),
active: proposalIndex[network].includes(proposalLink)
active: proposalIndex[network].includes(proposalLink),
proposalLink
};
}
164 changes: 153 additions & 11 deletions modules/executive/components/SpellEffectsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
/** @jsx jsx */

import { Box, Text, jsx, Link as ThemeUILink, Flex } from 'theme-ui';
import { getNetwork } from 'lib/maker';
import { getEtherscanLink } from 'lib/utils';
import { Box, Flex, Text, jsx, Link as ThemeUILink } from 'theme-ui';
import { Proposal, SpellData } from '../types';
import { useState } from 'react';
import { Icon as DaiUIIcon } from '@makerdao/dai-ui-icons';

import SkeletonThemed from 'modules/app/components/SkeletonThemed';
import { formatDateWithoutTime } from 'lib/datetime';

const CircleIcon = ({ name }) => (
<Flex
mr={2}
sx={theme => ({
background: theme.colors?.background,
borderRadius: '100%',
width: '34px',
minWidth: '34px',
height: '34px',
alignItems: 'center',
justifyContent: 'center'
})}
>
<DaiUIIcon name={name} size={3} color="primary" />
</Flex>
);

export function SpellEffectsTab({
proposal,
Expand Down Expand Up @@ -39,17 +59,139 @@ export function SpellEffectsTab({
</Flex>
)}
*/
const [expanded, setExpanded] = useState(false);

return (
<Box>
<Flex sx={{ mb: 3, overflow: 'auto' }}>
Spell at address
<ThemeUILink href={getEtherscanLink(getNetwork(), proposal.address, 'address')} target="_blank">
<Text sx={{ ml: 2, color: 'accentBlue', ':hover': { color: 'blueLinkHover' } }}>
{proposal.address}
</Text>
</ThemeUILink>
</Flex>
<Text
as="p"
variant="microHeading"
sx={{
mb: 4
}}
>
Spell Details
</Text>
<Box mb={4}>
<Text
as="p"
sx={{
fontWeight: 'semiBold'
}}
>
Executive Hash
</Text>

<Box
sx={theme => ({
background: theme.colors?.background,
p: 3,
transition: 'all 300ms linear',
overflow: 'hidden',
borderRadius: '3px'
})}
>
<Flex
sx={{
justifyContent: 'space-between'
}}
>
{spellData?.executiveHash ? (
<Text sx={{ mr: 2, fontWeight: 'semiBold', wordBreak: 'break-all' }}>
{spellData?.executiveHash}
</Text>
) : (
<SkeletonThemed width="300px" height="15px" />
)}

<Box sx={{ cursor: 'pointer', ml: 2, minWidth: '99px' }} onClick={() => setExpanded(!expanded)}>
<Text color={'textMuted'}>
What&apos;s this? <DaiUIIcon name={expanded ? 'chevron_up' : 'chevron_down'} size={2} />
</Text>
</Box>
</Flex>

{expanded && (
<Box sx={{ mt: 3 }}>
<Text as="p" color="textMuted">
This hash allows for manually verifying that the spell belongs to the correct Executive
Proposal. It can be reproduced by hashing the raw markdown text of this Executive Proposal.
The hash, the URL to the raw markdown text, and the correct hashing algorithm are all
registered on the blockchain in the spell smart contract.
</Text>
<Box sx={{ mt: 3 }}>
<ThemeUILink
href={'https://makerdao.world/en/learn/governance/audit-exec-spells'}
target="_blank"
>
<Text sx={{ color: 'accentBlue', ':hover': { color: 'blueLinkHover' } }}>
Learn more about auditing Executive Spells
<DaiUIIcon ml={2} name="arrowTopRight" size="2" />
</Text>
</ThemeUILink>
</Box>
</Box>
)}
</Box>
</Box>
<Box sx={{ display: 'flex', flexWrap: 'wrap' }}>
{'proposalLink' in proposal && (
<Box sx={{ width: ['100%', '50%'] }}>
<Text
as="p"
sx={{
fontWeight: 'semiBold'
}}
>
Proposal Markdown
</Text>
<Box>
<ThemeUILink href={proposal.proposalLink} target="_blank">
<Text sx={{ color: 'accentBlue', ':hover': { color: 'blueLinkHover' } }}>
View in GitHub
<DaiUIIcon ml={2} name="arrowTopRight" size="2" />
</Text>
</ThemeUILink>
</Box>
</Box>
)}
<Box sx={{ width: ['100%', '50%'] }}>
<Flex mb={3} mt={[3, 0]}>
<CircleIcon name="hourglass" />
<Box>
<Text
as="p"
sx={{
fontWeight: 'semiBold'
}}
>
Expiration
</Text>
<Text as="p" color="textMuted">
{formatDateWithoutTime(spellData?.eta)}
</Text>
</Box>
</Flex>
{spellData?.officeHours && (
<Flex mb={3}>
<CircleIcon name="clock" />
<Box>
<Text
as="p"
sx={{
fontWeight: 'semiBold'
}}
>
Office Hours Only
</Text>
<Text as="p" color="textMuted">
Spell will only be executed Monday through Friday between 14:00 and 21:00 UTC
</Text>
</Box>
</Flex>
)}
</Box>
</Box>
</Box>
);
}
1 change: 1 addition & 0 deletions modules/executive/types/proposal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type CMSProposal = {
proposalBlurb: string;
title: string;
date: string;
proposalLink: string;
};

export type RawAddressProposal = {
Expand Down
2 changes: 2 additions & 0 deletions modules/executive/types/spellData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export type SpellData = {
datePassed?: Date;
dateExecuted?: Date;
mkrSupport: number;
executiveHash?: string;
officeHours?: boolean;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@makerdao/dai": "^0.32.15",
"@makerdao/dai-plugin-governance": "^0.14.3",
"@makerdao/dai-plugin-governance": "^0.14.5",
"@makerdao/dai-plugin-ledger-web": "^0.9.10",
"@makerdao/dai-plugin-mcd": "^1.6.36",
"@makerdao/dai-plugin-trezor-web": "^0.9.7",
Expand Down
26 changes: 23 additions & 3 deletions pages/api/executive/analyze-spell/[address].ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ import { SpellData } from 'modules/executive/types/spellData';

// nextCastTime returns when the spell is available for execution, accounting for office hours (only works if the spell has not been executed yet)
// eta returns when the spell is available for execution, not account for office hours
// executiveHash returns the hash of the executive proposal
export const analyzeSpell = async (address: string, maker: any): Promise<SpellData> => {
const [done, nextCastTime, eta, datePassed, dateExecuted, mkrSupport] = await Promise.all([
const [
done,
nextCastTime,
eta,
datePassed,
dateExecuted,
mkrSupport,
executiveHash,
officeHours
] = await Promise.all([
maker
.service('spell')
.getDone(address)
Expand All @@ -33,7 +43,15 @@ export const analyzeSpell = async (address: string, maker: any): Promise<SpellDa
.getExecutionDate(address)
/* tslint:disable:no-empty */
.catch(_ => null), // this fails if the spell has not been executed
maker.service('chief').getApprovalCount(address)
maker.service('chief').getApprovalCount(address),
maker
.service('spell')
.getExecutiveHash(address)
.catch(_ => null),
maker
.service('spell')
.getOfficeHours(address)
.catch(_ => null)
]);

return {
Expand All @@ -43,7 +61,9 @@ export const analyzeSpell = async (address: string, maker: any): Promise<SpellDa
nextCastTime,
datePassed,
dateExecuted,
mkrSupport: mkrSupport.toBigNumber().toString()
mkrSupport: mkrSupport.toBigNumber().toString(),
executiveHash,
officeHours
};
};

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1341,10 +1341,10 @@
babel-runtime "^6.26.0"
bignumber.js "^8.1.1"

"@makerdao/dai-plugin-governance@^0.14.3":
version "0.14.3"
resolved "https://registry.yarnpkg.com/@makerdao/dai-plugin-governance/-/dai-plugin-governance-0.14.3.tgz#56709d7e53037af6777dfdd381c543305f5d37a4"
integrity sha512-drSyKzVdQOIlgUl32h29pBClIUDxLFwGFSBAAgYHJByaKbx3T5SI2xdhx4Hs/7o5gIokavRo4fjrTsCyKQIVIw==
"@makerdao/dai-plugin-governance@^0.14.5":
version "0.14.5"
resolved "https://registry.npmjs.org/@makerdao/dai-plugin-governance/-/dai-plugin-governance-0.14.5.tgz"
integrity sha512-utyTqnkMl1BdlKJ/0vkv6P/s72gj8nSGFCzpSDR2/7ZrbyLlNVbuxywXCGP03WYOwC7d1z7eZ2/E7EHGEnE/xQ==
dependencies:
"@makerdao/currency" "0.9.9"
"@makerdao/services-core" "^0.10.0"
Expand Down Expand Up @@ -13903,4 +13903,4 @@ yocto-queue@^0.1.0:
zustand@^2.2.3:
version "2.2.4"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-2.2.4.tgz#3b38f9192ae06e6a737ce2d78cbdc321b1c7f185"
integrity sha512-THkjmdAT3h7WzLGDFmC7LVdDOxplYXOdXy0rIEIe/Yn5NDUZNEpywurVdereUlL/hR0Yxm/P7uiSGNYw1eYxBA==
integrity sha512-THkjmdAT3h7WzLGDFmC7LVdDOxplYXOdXy0rIEIe/Yn5NDUZNEpywurVdereUlL/hR0Yxm/P7uiSGNYw1eYxBA==

0 comments on commit 6541e2b

Please sign in to comment.