From 281aeb30f75dfe45b2a18934f6758ea5bf6b6956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezi=C5=84ski?= Date: Tue, 18 Jan 2022 23:01:34 +0100 Subject: [PATCH] Voter weight plugin config (#481) * voter weight addin * vote weight plugin yarn * playaround wip * fixes * fix version * configuremint * chore: setup DEFAULT_GOVERNANCE_PROGRAM_ID in .env files * chore: rename useVoteRegistry to useVoterStakeRegistryClient * chore: * feat: Configure voter stake registry with default values * feat: crate mint config form * fix: hide V2 options from V1 program UI * feat: add voterWeightAddin to realm config proposal * fix: add voterWeightRecord to sdk api * feat: setup voter stake configure mint instruction Co-authored-by: Sebastian.Bor --- .gitignore | 6 + .vscode/settings.json | 1 + packages/common/src/contexts/wallet.tsx | 78 ++++---- packages/governance-sdk/package.json | 2 +- .../governance-sdk/src/governance/accounts.ts | 2 +- .../src/governance/withCastVote.ts | 4 + .../governance/withCreateAccountGovernance.ts | 4 + .../governance/withCreateMintGovernance.ts | 4 + .../governance/withCreateProgramGovernance.ts | 4 + .../src/governance/withCreateProposal.ts | 10 +- .../governance/withCreateTokenGovernance.ts | 4 + .../src/governance/withVoterWeightAccounts.ts | 25 +++ packages/governance/.env | 3 + packages/governance/.env.development | 1 + packages/governance/package.json | 5 +- .../governance/src/actions/registerRealm.ts | 3 +- .../configureVoterStakeRegistry.ts | 78 ++++++++ .../ModalFormAction/modalFormAction.tsx | 2 + .../votingMintConfigFormItem.tsx | 86 ++++++++ .../src/contexts/GovernanceContext.tsx | 10 +- .../src/hooks/useVoterStakeRegistryClient.ts | 36 ++++ packages/governance/src/tools/units.ts | 7 + .../src/tools/validators/voterWeightPlugin.ts | 11 ++ .../src/tools/voterStakeRegistry/accounts.ts | 14 ++ .../voterStakeRegistry/voterStakeRegistry.ts | 10 + .../home/buttons/registerRealmButton.tsx | 30 ++- .../accountInstructionsForm.tsx | 4 +- .../governanceInstructionForm.tsx | 30 ++- .../instructionInput/instructionInput.tsx | 19 +- .../instructionInput/instructionSelector.tsx | 6 +- .../instructionInput/mintInstructionsForm.tsx | 4 +- .../programInstructionsForm.tsx | 4 +- .../instructionInput/realmConfigForm.tsx | 30 ++- .../tokenInstructionsForm.tsx | 16 +- .../voterStakeConfigureMintForm.tsx | 90 +++++++++ .../voterStakeSetRegistrarForm.tsx | 75 +++++++ .../configureVoterStakeRegistryButton.tsx | 57 ++++++ .../views/realm/buttons/realmActionBar.tsx | 14 +- yarn.lock | 183 ++++++++++++++++-- 39 files changed, 888 insertions(+), 84 deletions(-) create mode 100644 packages/governance-sdk/src/governance/withVoterWeightAccounts.ts create mode 100644 packages/governance/.env.development create mode 100644 packages/governance/src/actions/voterStakeRegistry/configureVoterStakeRegistry.ts create mode 100644 packages/governance/src/components/voterStakeRegistry/votingMintConfigFormItem.tsx create mode 100644 packages/governance/src/hooks/useVoterStakeRegistryClient.ts create mode 100644 packages/governance/src/tools/validators/voterWeightPlugin.ts create mode 100644 packages/governance/src/tools/voterStakeRegistry/accounts.ts create mode 100644 packages/governance/src/tools/voterStakeRegistry/voterStakeRegistry.ts create mode 100644 packages/governance/src/views/proposal/components/instructionInput/voterStakeRegistry/voterStakeConfigureMintForm.tsx create mode 100644 packages/governance/src/views/proposal/components/instructionInput/voterStakeRegistry/voterStakeSetRegistrarForm.tsx create mode 100644 packages/governance/src/views/realm/buttons/configureVoterStakeRegistryButton.tsx diff --git a/.gitignore b/.gitignore index 0fbbdfef..215e4017 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,9 @@ yarn-debug.log* yarn-error.log* *.css *.css.map + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local diff --git a/.vscode/settings.json b/.vscode/settings.json index a79af11e..5d4dab63 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "cSpell.words": [ "Addin", "Blockhash", + "blockworks", "Lamport", "lamports", "localnet", diff --git a/packages/common/src/contexts/wallet.tsx b/packages/common/src/contexts/wallet.tsx index 926a0753..e159fd09 100644 --- a/packages/common/src/contexts/wallet.tsx +++ b/packages/common/src/contexts/wallet.tsx @@ -9,7 +9,7 @@ import { } from '@solana/wallet-adapter-base'; import { useWallet as useWalletBase, - WalletProvider as BaseWalletProvider + WalletProvider as BaseWalletProvider, } from '@solana/wallet-adapter-react'; import { getLedgerWallet, @@ -22,10 +22,19 @@ import { Wallet, WalletName, } from '@solana/wallet-adapter-wallets'; -import { Button, Modal } from "antd"; -import React, { createContext, FC, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react'; -import { notify } from "../utils"; -import { useConnectionConfig } from "./connection"; +import { Button, Modal } from 'antd'; +import React, { + createContext, + FC, + ReactNode, + useCallback, + useContext, + useEffect, + useMemo, + useState, +} from 'react'; +import { notify } from '../utils'; +import { useConnectionConfig } from './connection'; export interface WalletContextState extends WalletAdapterProps { wallets: Wallet[]; @@ -43,20 +52,25 @@ export interface WalletContextState extends WalletAdapterProps { signMessage: MessageSignerWalletAdapterProps['signMessage'] | undefined; } -export function useWallet (): WalletContextState { +export function useWallet(): WalletContextState { return useWalletBase() as WalletContextState; } export { SignerWalletAdapter, WalletNotConnectedError }; -export type WalletSigner = Pick; +export type WalletSigner = Pick< + SignerWalletAdapter, + 'publicKey' | 'signTransaction' | 'signAllTransactions' +>; export interface WalletModalContextState { visible: boolean; setVisible: (open: boolean) => void; } -export const WalletModalContext = createContext({} as WalletModalContextState); +export const WalletModalContext = createContext( + {} as WalletModalContextState, +); export function useWalletModal(): WalletModalContextState { return useContext(WalletModalContext); @@ -76,20 +90,23 @@ export const WalletModal = () => { onCancel={close} width={400} > - {wallets.map((wallet) => { + {wallets.map(wallet => { return (