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

Feat/holographic consensus #339

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9235c83
refactor: replaced chevron button with common implementation
dcrescimbeni Mar 16, 2023
6a7502a
feat: added card divider and gap property to flex element
dcrescimbeni Mar 16, 2023
8593cb4
test: updated snapshots
dcrescimbeni Mar 16, 2023
3bbc6b7
feat: added speedometer library
dcrescimbeni Mar 16, 2023
393c910
feat: formatted scrollbar for sidebar sections
dcrescimbeni Mar 16, 2023
b5d9cc5
feat: hardcoded draft of holographic consensus component
dcrescimbeni Mar 17, 2023
4073021
feat: added slider component
dcrescimbeni Mar 17, 2023
a8ceb29
feat: replaced "medium" for "bold" in font weight to match figma designs
dcrescimbeni Mar 17, 2023
8cf2eb1
feat: added Text component
dcrescimbeni Mar 17, 2023
a9c980b
feat: added modal
dcrescimbeni Mar 17, 2023
11db169
feat: added translations and updated todo list
dcrescimbeni Mar 17, 2023
26d6f90
Merge branch 'develop' into feat/holographic-consensus
dcrescimbeni Mar 20, 2023
4c3b17a
feat: added subDAO property to Proposal type
dcrescimbeni Mar 20, 2023
42abc8d
feat: added staking token address to voting machine schema
dcrescimbeni Mar 20, 2023
ccdffe3
feat: added option to get data from only one scheme in useGetSubDAOs …
dcrescimbeni Mar 20, 2023
5268d44
feat: added token symbol, and error and loading handlers for the comp…
dcrescimbeni Mar 20, 2023
b4b1c87
ci: added DXD token to localhost config
dcrescimbeni Mar 20, 2023
a6af2c8
feat: fetch token symbol
dcrescimbeni Mar 20, 2023
9c56355
feat: token logo
dcrescimbeni Mar 20, 2023
bbdc022
feat: fetch user balance, staking amount logic and conditional staking
dcrescimbeni Mar 20, 2023
4302bab
fix(VotingMachine-mapping): fixed Voting Machine instance not being c…
dcrescimbeni Mar 21, 2023
2eb2d77
feat(useBigNumber): added non-hook version of useBigNumberToNumber an…
dcrescimbeni Mar 21, 2023
d655b36
feat: added stakes and extracted types
dcrescimbeni Mar 21, 2023
3c94e4d
feat: added non-hook version of useBigNumberToString
dcrescimbeni Mar 21, 2023
907dda1
feat: added totalStaked in proposal type and holographic consensus card
dcrescimbeni Mar 21, 2023
5922d68
feat: speedometer value calculation
dcrescimbeni Mar 21, 2023
fa4a183
feat: we have staking!
dcrescimbeni Mar 23, 2023
06064f8
fix: fix stake detail with duplicated keys
dcrescimbeni Mar 23, 2023
e825516
feat: added proposal state from voting machine
dcrescimbeni Mar 23, 2023
a90a539
feat: added colors to proposal state text
dcrescimbeni Mar 23, 2023
50a0c94
fix: translations
dcrescimbeni Mar 23, 2023
e24c8af
fix: fixed modal header and click toggles stake detail visibility
dcrescimbeni Mar 23, 2023
c287de8
feat: potential reward calculation
dcrescimbeni Mar 24, 2023
0617140
feat: show ENS or address in stake detail
dcrescimbeni Mar 24, 2023
047ed74
feat: after proposal creation, it stakes daoBounty amount in "NO" option
dcrescimbeni Mar 24, 2023
a17dfc6
fix: refactored styles and simplified logic
dcrescimbeni Mar 24, 2023
56dd1e7
fix: merge
dcrescimbeni Mar 27, 2023
4cd1d93
feat: added voting machine ID to useGetSubDAO hook
dcrescimbeni Mar 27, 2023
be6eac3
feat: added useApproveTokens to hook store
dcrescimbeni Mar 27, 2023
8a139cf
feat: added approve logic to staking
dcrescimbeni Mar 27, 2023
73f90c8
fix: fix calculatePotentialReward bug and changed component name
dcrescimbeni Mar 27, 2023
8eb7fce
ci: moved DXD token transfer to development.js script on dev-scripts
dcrescimbeni Mar 27, 2023
0db05c9
fix: bug where it crashed because there were no stakes
dcrescimbeni Mar 27, 2023
badccfb
fix: message if there are no stakes
dcrescimbeni Mar 27, 2023
ce54c42
fix: minor changes
dcrescimbeni Mar 27, 2023
02e5674
fix: added spanish translations
dcrescimbeni Mar 30, 2023
ebcc56a
fix: refactored code to prevent duplication and fixed translation text
dcrescimbeni Mar 30, 2023
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
9 changes: 8 additions & 1 deletion apps/dao-subgraph/src/mappings/DAOController/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { Scheme, VotingMachine } from '../../types/schema';
import { Scheme as SchemeContract } from '../../types/DAOController/Scheme';
import { VotingMachine as VotingMachineContract } from '../../types/DAOController/VotingMachine';

import { Scheme as SchemeTemplate } from '../../types/templates';
import {
Scheme as SchemeTemplate,
VotingMachine as VotingMachineTemplate,
} from '../../types/templates';

export function handleRegisterScheme(event: RegisterScheme): void {
const controllerAddress = event.address;
Expand Down Expand Up @@ -66,6 +69,9 @@ export function handleRegisterScheme(event: RegisterScheme): void {
votingMachine = new VotingMachine(votingMachineAddress.toHexString());
}

votingMachine.stakingTokenAddress = votingMachineContract
.stakingToken()
.toHexString();
votingMachine.queuedVoteRequiredPercentage =
votingParams.getQueuedVoteRequiredPercentage();
votingMachine.queuedVotePeriodLimit = votingParams.getQueuedVotePeriodLimit();
Expand All @@ -83,6 +89,7 @@ export function handleRegisterScheme(event: RegisterScheme): void {
votingMachine.save();

SchemeTemplate.create(schemeAddress);
VotingMachineTemplate.create(votingMachineAddress);
}

export function handleUnregisterScheme(event: UnregisterScheme): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Scheme @entity {

type VotingMachine @entity {
id: ID!
stakingTokenAddress: String!
queuedVoteRequiredPercentage: BigInt
queuedVotePeriodLimit: BigInt
boostedVotePeriodLimit: BigInt
Expand Down
21 changes: 20 additions & 1 deletion apps/dao-subgraph/src/mappings/Scheme/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Address, Bytes } from '@graphprotocol/graph-ts';
import { Address, Bytes, BigInt, log } from '@graphprotocol/graph-ts';
import { ProposalStateChange } from '../../types/DAOController/Scheme';
import {
Proposal,
Stake,
StateLog,
VotingMachineProposalStateLog,
} from '../../types/schema';
Expand Down Expand Up @@ -54,6 +55,24 @@ export function handleProposalStateChange(event: ProposalStateChange): void {
let proposal = Proposal.load(proposalId.toHexString());
if (!proposal) {
proposal = new Proposal(proposalId.toHexString());

// Every proposal starts with a stake on the "NO" option equal to daoBounty
const stakeId = `${proposalId.toHexString()}-${schemeAddress.toHexString()}-${
event.block.timestamp
}-stake`;

const stake = new Stake(stakeId);
stake.amount = new BigInt(0);

stake.proposal = proposalId.toHexString();
stake.avatar = schemeContract.avatar().toHexString();
stake.staker = schemeAddress.toHexString();
stake.option = BigInt.fromString('1'); // NO option
stake.amount = proposalDataFromVotingMachine.getDaoBounty();
stake.timestamp = event.block.timestamp;
stake.txId = event.transaction.hash.toHexString();

stake.save();
}

// Scheme data
Expand Down
4 changes: 2 additions & 2 deletions apps/davi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"react": "^18.2.0",
"react-app-rewired": "^2.1.8",
"react-countdown": "^2.3.2",
"react-d3-speedometer": "^1.1.0",
"react-datepicker": "^4.8.0",
"react-device-detect": "^2.1.2",
"react-diff-viewer": "^3.1.1",
Expand All @@ -133,11 +134,11 @@
"react-switch": "^7.0.0",
"react-toastify": "^8.1.0",
"react-virtuoso": "^2.16.5",
"showdown": "^2.1.0",
"styled-components": "^5.3.5",
"swr": "^1.1.2",
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"showdown": "^2.1.0",
"turndown": "^7.1.1",
"typechain-target-ethers-v5": "^5.0.1",
"typescript": "^4.9.3",
Expand Down Expand Up @@ -233,4 +234,3 @@
]
}
}

12 changes: 12 additions & 0 deletions apps/davi/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,14 @@
"increaseVotingPower": "Increase Voting Power",
"locking": {
"locked": "Locked",
"lock": "Lock",
"unlocked": "Unlocked",
"unlockedIn": "Unlocked in",
"staked": "Staked",
"withdraw": "Withdraw",
"balance": "Balance",
"unlockDate": "Unlock Date",
"unlockTime": "Unlock time",
"spending": "Spending",
"max": "Max",
"stakeTokens": "Stake {{token}} tokens",
Expand Down Expand Up @@ -402,6 +404,16 @@
"errorFetchingSchemes": "Error while fetching schemes",
"daoHasNoSchemes": "This DAO has no schemes registered"
},
"holographicConsensus": {
"predictions": "Predictions",
"confirmPrediction": "Confirm prediction",
"placeYourPrediction": "Place your prediction to steer the proposal",
"potentialReward": "Potential reward",
"lockWarning": "Your prediction will be locked until the proposal ends and you could lose your DXD if your prediction is wrong",
"stakeOnProposal": "Stake on proposal",
"youCannotChangeYourPrediction": "You cannot change your prediction since you already staked in this proposal",
"thereAreNoStakes": "There are no stakes for this option"
},
"inputValidation": {
"recipientAddressIsRequired": "Recipient address is required",
"amountIsRequired": "Amount is required",
Expand Down
15 changes: 14 additions & 1 deletion apps/davi/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,15 @@
"yourVotingPower": "Tu Poder de Votación",
"increaseVotingPower": "Incrementar Poder de Votación",
"locking": {
"lock": "Bloquear",
"locked": "Bloqueado",
"unlocked": "Desbloqueado",
"unlockedIn": "Desbloqueado en",
"staked": "Invertido",
"withdraw": "Retirar",
"balance": "Balance",
"unlockDate": "Fecha de desbloqueo",
"unlockTime": "Tiempo de desbloqueo",
"spending": "Gasto",
"max": "Max",
"stakeTokens": "Invertir {{token}} tokens",
Expand Down Expand Up @@ -431,5 +433,16 @@
},
"loading": "Cargando...",
"showMore": "Mostrar más",
"showLess": "Mostrar menos"
"showLess": "Mostrar menos",
"holographicConsensus": {
"confirmPrediction": "Confirmar predicción",
"potentialReward": "Recompensa potencial",
"stakeOnProposal": "Apostar en la propuesta",
"predictions": "Predicciones",
"thereAreNoStakes": "No hay apuestas en esta opción",
"lockWarning": "Tu predicción estará bloqueada hasta que la propuesta termine y podrías perder tu DXD si tu predicción es incorrecta",
"placeYourPrediction": "Ingresa tu predicción para dirigir la propuesta",
"youCannotChangeYourPrediction": "No puedes cambiar tu predicción porque ya apostaste en esta propuesta"
}
}

12 changes: 12 additions & 0 deletions apps/davi/src/Modules/Guilds/pages/Proposal/Proposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Flex } from 'components/primitives/Layout';
import { IconButton } from 'components/primitives/Button';
import { getBlockExplorerUrl } from 'provider';
import { useSearchParams } from 'react-router-dom';
import { HolographicConsensusCard } from 'components/HolographicConsensusCard/HolographicConsensusCard';

const ProposalPage: React.FC = () => {
const {
Expand All @@ -52,6 +53,7 @@ const ProposalPage: React.FC = () => {
useTimeDetail,
},
},
capabilities: { consensus },
} = useHookStoreProvider();
const { t } = useTranslation();
const { connector } = useAccount();
Expand Down Expand Up @@ -202,6 +204,16 @@ const ProposalPage: React.FC = () => {
guildConfig={guildConfig}
quorum={quorum}
/>
{consensus === 'holographic' && (
<HolographicConsensusCard
proposalStakeDetails={proposal?.stakes}
proposalTotalStakes={proposal?.totalStaked}
schemeId={proposal?.subDao}
proposalId={proposalId}
proposalState={proposal?.holographicConsensusState}
daoBounty={proposal?.daoBounty}
/>
)}
</SidebarContent>
</PageContainer>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import moment from 'moment';
import { BigNumber } from 'ethers';
import { useTranslation } from 'react-i18next';
import { getSchemesQuery } from '.graphclient';
import { getAllSchemesQuery } from '.graphclient';
import {
InfoDetail,
InfoDetailMuted,
} from 'components/ProposalInfoCard/ProposalInfoCard.styled';
import { CardBody, SchemePropertiesGrid } from './SchemeSelection.styled';

type Scheme = getSchemesQuery['dao']['schemes'][0];
type Scheme = getAllSchemesQuery['dao']['schemes'][0];

const humanizedTime = (time: string) => {
const timeInSeconds = Number.parseInt(time);
Expand Down
25 changes: 19 additions & 6 deletions apps/davi/src/Modules/Guilds/pages/Treasury/Treasury.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@ jest.mock('Modules/Guilds/Hooks/useTypedParams', () => ({
}),
}));

let mockHook;

jest.mock('hooks/Guilds/erc20/useAllERC20Balances', () => ({
useAllERC20Balances: () => ({
data: [MOCK_TOKEN_INFO],
isLoading: false,
isError: false,
}),
useAllERC20Balances: () => mockHook,
}));

describe('Treasury Page', () => {
it(`Should render without data`, async () => {
it(`Should render with token data`, async () => {
mockHook = {
data: [MOCK_TOKEN_INFO],
isLoading: false,
isError: false,
};
const { container } = render(<Treasury />);
expect(container).toMatchSnapshot();
});

it(`Should render message when there are no tokens`, async () => {
mockHook = {
data: [],
isLoading: false,
isError: false,
};
const { container } = render(<Treasury />);
expect(container).toMatchSnapshot();
});
Expand Down
Loading