Skip to content

Commit

Permalink
Releave Gov 2 (#421)
Browse files Browse the repository at this point in the history
* ref: wallet connect id

* ref: removed comment

* feat: added new proxies

* ref: smaller font size for select

* fix: parameter

* wip

* ref: deps

* ref: linting

* ci: removed ci

* feat: updated contracts

* fix: more max witdh for wallet input
  • Loading branch information
MrX-SNX authored Aug 30, 2024
1 parent bd465c0 commit 1e9e98e
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 1,216 deletions.
108 changes: 54 additions & 54 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,56 +120,56 @@ jobs:
- run: git diff --name-only --exit-code
- run: yarn typecheck

governance-e2e:
working_directory: /tmp/app
docker:
- image: cypress/included:<< pipeline.parameters.cypress-version >>
resource_class: large
environment:
NODE_ENV: test
TESTNET: 1
steps:
- checkout
- install-foundry
- yarn-install

- run:
name: Run server localhost:3000
working_directory: /tmp/app/governance/ui
command: CI=true yarn start
background: true

- run:
name: Run anvil localhost:8545
command: 'anvil --fork-url https://testnet.snaxchain.io --fork-block-number 296528'
background: true

- run:
name: Wait for server localhost:3000
command: wget --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 http://localhost:3000

- run:
name: Wait for anvil localhost:8545
command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545

- run:
working_directory: /tmp/app/governance/cypress
command: cypress run --e2e --browser chrome

- store_test_results:
path: 'governance/cypress/cypress/reports'

- store_artifacts:
path: 'governance/cypress/.nyc_output'
destination: 'coverage'

- store_artifacts:
path: 'governance/cypress/cypress/screenshots'
destination: 'screenshots'

- store_artifacts:
path: 'governance/cypress/cypress/videos'
destination: 'videos'
# governance-e2e:
# working_directory: /tmp/app
# docker:
# - image: cypress/included:<< pipeline.parameters.cypress-version >>
# resource_class: large
# environment:
# NODE_ENV: test
# TESTNET: 1
# steps:
# - checkout
# - install-foundry
# - yarn-install

# - run:
# name: Run server localhost:3000
# working_directory: /tmp/app/governance/ui
# command: CI=true yarn start
# background: true

# - run:
# name: Run anvil localhost:8545
# command: 'anvil --fork-url https://testnet.snaxchain.io --fork-block-number 296528'
# background: true

# - run:
# name: Wait for server localhost:3000
# command: wget --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 http://localhost:3000

# - run:
# name: Wait for anvil localhost:8545
# command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545

# - run:
# working_directory: /tmp/app/governance/cypress
# command: cypress run --e2e --browser chrome

# - store_test_results:
# path: 'governance/cypress/cypress/reports'

# - store_artifacts:
# path: 'governance/cypress/.nyc_output'
# destination: 'coverage'

# - store_artifacts:
# path: 'governance/cypress/cypress/screenshots'
# destination: 'screenshots'

# - store_artifacts:
# path: 'governance/cypress/cypress/videos'
# destination: 'videos'

liquidity-e2e:
parameters:
Expand Down Expand Up @@ -269,7 +269,7 @@ jobs:
- run: rm -rf /tmp/cov
- run: yarn download-cci-coverage tests /tmp/cov || true
- run: yarn download-cci-coverage liquidity-cy /tmp/cov || true
# - run: yarn download-cci-coverage governance-cy /tmp/cov || true
# - run: yarn download-cci-coveragegovernance-cy /tmp/cov || true
- run: yarn download-cci-coverage liquidity-e2e-base-mainnet /tmp/cov || true
- run: yarn download-cci-coverage liquidity-e2e-optimism-mainnet /tmp/cov || true
- run: mkdir -p /tmp/cov
Expand Down Expand Up @@ -307,8 +307,8 @@ workflows:
- typecheck
- tests
- liquidity-cy
- governance-e2e:
name: governance-e2e-snax-testnet
# - governance-e2e:
# name: governance-e2e-snax-testnet
- liquidity-e2e:
name: liquidity-e2e-base-mainnet
chainId: 8453
Expand All @@ -323,7 +323,7 @@ workflows:
requires: [
tests,
liquidity-cy,
governance-e2e-snax-testnet,
# governance-e2e-snax-testnet,
liquidity-e2e-base-mainnet,
#liquidity-e2e-sepolia,
]
Expand Down
18 changes: 11 additions & 7 deletions governance/cypress/cypress/tasks/changePeriod.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { ethers, Wallet } from 'ethers';
import { getCouncilContract } from '../../../ui/src/utils/contracts';
import { Contract, ethers, Wallet } from 'ethers';
import { electionModuleABITest } from '../../../ui/src/utils/abi';

export async function changePeriod({ council, period }) {
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const proxy = getCouncilContract(council, 13001);
const proxy = {
spartan: new Contract('0xBC85F11300A8EF619592fD678418Ec4eF26FBdFD', electionModuleABITest),
ambassador: new Contract('0xCdbEf5753cE3CEbF361e143117e345ADd7498F80', electionModuleABITest),
treasury: new Contract('0xe3aB2C6F1C9E46Fb53eD6b297c6fff68e935B161', electionModuleABITest),
};
const block = await provider.getBlock('latest');
const signer = new Wallet(
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
provider
);
if (period === 'admin') {
await proxy
await proxy[council]
.connect(signer)
.Epoch_setEpochDates(
0,
Expand All @@ -20,7 +24,7 @@ export async function changePeriod({ council, period }) {
block.timestamp + 30000
);
} else if (period === 'nomination') {
await proxy
await proxy[council]
.connect(signer)
.Epoch_setEpochDates(
0,
Expand All @@ -30,7 +34,7 @@ export async function changePeriod({ council, period }) {
block.timestamp + 20000
);
} else if (period === 'voting') {
await proxy
await proxy[council]
.connect(signer)
.Epoch_setEpochDates(
0,
Expand All @@ -40,7 +44,7 @@ export async function changePeriod({ council, period }) {
block.timestamp + 10000
);
} else {
await proxy
await proxy[council]
.connect(signer)
.Epoch_setEpochDates(
0,
Expand Down
2 changes: 1 addition & 1 deletion governance/cypress/cypress/tasks/prepareVotingPower.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCouncilContract, SnapshotRecordContract } from '../../../ui/src/util

export async function prepareVotingPower({ council }) {
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const proxy = getCouncilContract(council, 13001);
const proxy = getCouncilContract(council);
const signer = new Wallet(
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
provider
Expand Down
2 changes: 1 addition & 1 deletion governance/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.ts",
"version": "0.0.1",
"scripts": {
"anvil:snax": "anvil --fork-url https://testnet.snaxchain.io --fork-block-number 296528",
"anvil:snax": "anvil --fork-url https://testnet.snaxchain.io --fork-block-number 296428",
"e2e": "cypress open --e2e --browser electron"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion governance/ui/src/components/CouncilTabs/CouncilSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const CouncilsSelect = ({ activeCouncil }: { activeCouncil: CouncilSlugs
<CouncilImage imageUrl={slugToImageUrl(activeCouncil)} mr="10px" />
<Text
fontFamily="heading"
fontSize={{ base: 'sm', md: 'md' }}
fontSize={{ base: 'xs', md: 'md' }}
lineHeight="28px"
fontWeight={700}
mr="12px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function UserProfileForm() {
mr="1"
fontSize="14px"
fontWeight="400"
maxW="300px"
maxW="400px"
textOverflow="ellipsis"
whiteSpace="nowrap"
overflow="hidden"
Expand Down
2 changes: 1 addition & 1 deletion governance/ui/src/mutations/useCastVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function useCastVotes(
const isMC = process.env.CI === 'true' ? true : isMotherchain(network.id);
try {
const electionModules = councils.map((council) =>
getCouncilContract(council, network.id).connect(signer)
getCouncilContract(council).connect(signer)
);
const prepareBallotData = councils
.map((council, index) => {
Expand Down
2 changes: 1 addition & 1 deletion governance/ui/src/mutations/useDeclareVotingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function useDeclareVotingPower(council: CouncilSlugs) {
mutationFn: async () => {
if (signer && network) {
try {
const electionModule = getCouncilContract(council, network.id).connect(signer);
const electionModule = getCouncilContract(council).connect(signer);
const voter = await signer.getAddress();
await electionModule.prepareBallotWithSnapshot(
SnapshotRecordContract(network.id, council)?.address,
Expand Down
7 changes: 3 additions & 4 deletions governance/ui/src/mutations/useEditNomination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNetwork, useSigner } from '../queries/useWallet';
import { useSigner } from '../queries/useWallet';
import { getCouncilContract } from '../utils/contracts';
import { CouncilSlugs } from '../utils/councils';
import { useToast } from '@chakra-ui/react';
Expand All @@ -17,14 +17,13 @@ export default function useEditNomination({
const signer = useSigner();
const toast = useToast();
const multicall = useMulticall();
const { network } = useNetwork();
return useMutation({
mutationFn: async () => {
if (signer) {
const txs = [];
if ((nextNomination && currentNomination) || (!nextNomination && currentNomination)) {
txs.push({
target: getCouncilContract(currentNomination, network?.id).address,
target: getCouncilContract(currentNomination).address,
callData:
getCouncilContract(currentNomination).interface.encodeFunctionData(
'withdrawNomination'
Expand All @@ -33,7 +32,7 @@ export default function useEditNomination({
}
if (nextNomination) {
txs.push({
target: getCouncilContract(nextNomination, network?.id).address,
target: getCouncilContract(nextNomination).address,
callData: getCouncilContract(nextNomination).interface.encodeFunctionData('nominate'),
});
}
Expand Down
5 changes: 2 additions & 3 deletions governance/ui/src/mutations/useNominateSelf.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { getCouncilContract } from '../utils/contracts';
import { useNetwork, useSigner } from '../queries/useWallet';
import { useSigner } from '../queries/useWallet';
import { useToast } from '@chakra-ui/react';
import { utils } from 'ethers';

export default function useNominateSelf(council: CouncilSlugs, address?: string) {
const query = useQueryClient();
const signer = useSigner();
const toast = useToast();
const { network } = useNetwork();

return useMutation({
mutationFn: async () => {
if (signer) {
try {
const tx = await getCouncilContract(council, network?.id)
const tx = await getCouncilContract(council)
.connect(signer)
.nominate({
maxPriorityFeePerGas: utils.parseUnits('1', 'gwei'),
Expand Down
1 change: 1 addition & 0 deletions governance/ui/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './useGetUserBallot';
export * from './useGetUserDetailsQuery';
export * from './useGetUserVotingPower';
export * from './useWallet';
export * from './useGetHistoricalVotes';
18 changes: 18 additions & 0 deletions governance/ui/src/queries/useGetHistoricalVotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { useNetwork } from './useWallet';

const testnetURL = 'https://api.synthetix.io/v3/snax-testnet/votes';

export function useGetHistoricalVotes(council: CouncilSlugs) {
const { network } = useNetwork();
return useQuery({
queryKey: ['historical-votes', council, network?.id],
queryFn: async () => {
const res = await fetch(network?.id === 2192 ? testnetURL : testnetURL);
const votes = await res.json();
return votes;
},
staleTime: 900000,
});
}
3 changes: 0 additions & 3 deletions governance/ui/src/queries/useGetUserDetailsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export async function getUserDetails<T extends string | string[]>(
return {
...data,
delegationPitch: foundPitch,
// foundPitch.find(
// (pitch) => pitch[0]?.address.toLowerCase() === data.address.toLowerCase()
// )[0]?.delegationPitch || '',
};
} catch (error) {
console.error(error);
Expand Down
4 changes: 1 addition & 3 deletions governance/ui/src/queries/useGetUserVotingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export function useGetUserVotingPower(council: CouncilSlugs) {
if (!activeWallet || !provider || !network?.id) return;

try {
const electionModule = getCouncilContract(council, network.id).connect(
motherShipProvider(network.id)
);
const electionModule = getCouncilContract(council).connect(motherShipProvider(network.id));
const isMC = process.env.CI === 'true' ? true : isMotherchain(network.id);

const electionId = await electionModule.getEpochIndex();
Expand Down
Loading

0 comments on commit 1e9e98e

Please sign in to comment.