Skip to content

Commit

Permalink
Feature/release loader and council (#643)
Browse files Browse the repository at this point in the history
* release loader

* hide multi vote for nfts

* vote with council alone when plugin is on

* fix council

* release nfts addon
  • Loading branch information
abrzezinski94 committed Apr 28, 2022
1 parent b858ce7 commit 646e4f9
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Strategies/components/MangoDepositComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const MangoDepositComponent = ({
},
realm!,
governedTokenAccount!,
ownTokenRecord.pubkey,
ownTokenRecord,
defaultProposalMint!,
governedTokenAccount!.governance!.account!.proposalCount,
prerequisiteInstructions,
Expand Down
9 changes: 7 additions & 2 deletions Strategies/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { MangoAccount } from '@blockworks-foundation/mango-client'
import { ProgramAccount, Realm, RpcContext } from '@solana/spl-governance'
import {
ProgramAccount,
Realm,
RpcContext,
TokenOwnerRecord,
} from '@solana/spl-governance'
import { PublicKey, TransactionInstruction } from '@solana/web3.js'
import { VotingClient } from '@utils/uiTypes/VotePlugin'
import { AssetAccount } from '@utils/uiTypes/assets'
Expand Down Expand Up @@ -31,7 +36,7 @@ export type HandleCreateProposalWithStrategy = (
form: MNGODepositForm,
realm: ProgramAccount<Realm>,
treasuaryAccount: AssetAccount,
tokenOwnerRecord: PublicKey,
tokenOwnerRecord: ProgramAccount<TokenOwnerRecord>,
governingTokenMint: PublicKey,
proposalIndex: number,
prerequisiteInstructions: TransactionInstruction[],
Expand Down
18 changes: 8 additions & 10 deletions actions/castVote.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {
Keypair,
PublicKey,
Transaction,
TransactionInstruction,
} from '@solana/web3.js'
import { Keypair, Transaction, TransactionInstruction } from '@solana/web3.js'
import {
ChatMessageBody,
getGovernanceProgramVersion,
GOVERNANCE_CHAT_PROGRAM_ID,
Proposal,
Realm,
TokenOwnerRecord,
withPostChatMessage,
YesNoVote,
} from '@solana/spl-governance'
Expand All @@ -29,7 +25,7 @@ export async function castVote(
{ connection, wallet, programId, walletPubkey }: RpcContext,
realm: ProgramAccount<Realm>,
proposal: ProgramAccount<Proposal>,
tokeOwnerRecord: PublicKey,
tokeOwnerRecord: ProgramAccount<TokenOwnerRecord>,
yesNoVote: YesNoVote,
message?: ChatMessageBody | undefined,
votingPlugin?: VotingClient
Expand All @@ -49,7 +45,8 @@ export async function castVote(
//will run only if any plugin is connected with realm
const plugin = await votingPlugin?.withCastPluginVote(
instructions,
proposal.pubkey
proposal,
tokeOwnerRecord
)
await withCastVote(
instructions,
Expand All @@ -59,7 +56,7 @@ export async function castVote(
proposal.account.governance,
proposal.pubkey,
proposal.account.tokenOwnerRecord,
tokeOwnerRecord,
tokeOwnerRecord.pubkey,
governanceAuthority,
proposal.account.governingTokenMint,
Vote.fromYesNoVote(yesNoVote),
Expand All @@ -71,6 +68,7 @@ export async function castVote(
if (message) {
const plugin = await votingPlugin?.withUpdateVoterWeightRecord(
instructions,
tokeOwnerRecord,
'commentProposal'
)
await withPostChatMessage(
Expand All @@ -81,7 +79,7 @@ export async function castVote(
realm.pubkey,
proposal.account.governance,
proposal.pubkey,
tokeOwnerRecord,
tokeOwnerRecord.pubkey,
governanceAuthority,
payer,
undefined,
Expand Down
7 changes: 4 additions & 3 deletions actions/chat/postMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
GOVERNANCE_CHAT_PROGRAM_ID,
Proposal,
Realm,
TokenOwnerRecord,
} from '@solana/spl-governance'
import { ChatMessageBody } from '@solana/spl-governance'
import { withPostChatMessage } from '@solana/spl-governance'
Expand All @@ -20,7 +21,7 @@ export async function postChatMessage(
{ connection, wallet, programId, walletPubkey }: RpcContext,
realm: ProgramAccount<Realm>,
proposal: ProgramAccount<Proposal>,
tokeOwnerRecord: PublicKey,
tokeOwnerRecord: ProgramAccount<TokenOwnerRecord>,
body: ChatMessageBody,
replyTo?: PublicKey,
client?: VotingClient
Expand All @@ -30,10 +31,10 @@ export async function postChatMessage(

const governanceAuthority = walletPubkey
const payer = walletPubkey

//will run only if plugin is connected with realm
const plugin = await client?.withUpdateVoterWeightRecord(
instructions,
tokeOwnerRecord,
'commentProposal'
)

Expand All @@ -45,7 +46,7 @@ export async function postChatMessage(
realm.pubkey,
proposal.account.governance,
proposal.pubkey,
tokeOwnerRecord,
tokeOwnerRecord.pubkey,
governanceAuthority,
payer,
replyTo,
Expand Down
10 changes: 6 additions & 4 deletions actions/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Governance,
ProgramAccount,
Realm,
TokenOwnerRecord,
VoteType,
withCreateProposal,
} from '@solana/spl-governance'
Expand Down Expand Up @@ -61,7 +62,7 @@ export const createProposal = async (
{ connection, wallet, programId, walletPubkey }: RpcContext,
realm: ProgramAccount<Realm>,
governance: PublicKey,
tokenOwnerRecord: PublicKey,
tokenOwnerRecord: ProgramAccount<TokenOwnerRecord>,
name: string,
descriptionLink: string,
governingTokenMint: PublicKey,
Expand Down Expand Up @@ -99,6 +100,7 @@ export const createProposal = async (
//will run only if plugin is connected with realm
const plugin = await client?.withUpdateVoterWeightRecord(
instructions,
tokenOwnerRecord,
'createProposal'
)

Expand All @@ -108,7 +110,7 @@ export const createProposal = async (
programVersion,
realm.pubkey!,
governance,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
name,
descriptionLink,
governingTokenMint,
Expand All @@ -126,7 +128,7 @@ export const createProposal = async (
programId,
programVersion,
proposalAddress,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
governanceAuthority,
signatory,
payer
Expand Down Expand Up @@ -157,7 +159,7 @@ export const createProposal = async (
programVersion,
governance,
proposalAddress,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
governanceAuthority,
index,
0,
Expand Down
8 changes: 5 additions & 3 deletions actions/createTreasuryAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
GovernanceConfig,
ProgramAccount,
Realm,
TokenOwnerRecord,
withCreateGovernance,
withCreateNativeTreasury,
} from '@solana/spl-governance'
Expand All @@ -25,7 +26,7 @@ export const createTreasuryAccount = async (
realm: ProgramAccount<Realm>,
mint: PublicKey | null,
config: GovernanceConfig,
tokenOwnerRecord: PublicKey,
tokenOwnerRecord: ProgramAccount<TokenOwnerRecord>,
client?: VotingClient
): Promise<PublicKey> => {
const instructions: TransactionInstruction[] = []
Expand All @@ -41,6 +42,7 @@ export const createTreasuryAccount = async (
//will run only if plugin is connected with realm
const plugin = await client?.withUpdateVoterWeightRecord(
instructions,
tokenOwnerRecord,
'createGovernance'
)

Expand All @@ -66,7 +68,7 @@ export const createTreasuryAccount = async (
config,
true,
walletPubkey,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
walletPubkey,
governanceAuthority,
plugin?.voterWeightPk
Expand All @@ -78,7 +80,7 @@ export const createTreasuryAccount = async (
realm.pubkey,
undefined,
config,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
walletPubkey,
governanceAuthority,
plugin?.voterWeightPk
Expand Down
6 changes: 4 additions & 2 deletions actions/registerProgramGovernance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GovernanceType,
ProgramAccount,
Realm,
TokenOwnerRecord,
} from '@solana/spl-governance'
import { GovernanceConfig } from '@solana/spl-governance'
import { withCreateProgramGovernance } from '@solana/spl-governance'
Expand All @@ -23,7 +24,7 @@ export const registerProgramGovernance = async (
governedAccount: PublicKey,
config: GovernanceConfig,
transferAuthority: boolean,
tokenOwnerRecord: PublicKey,
tokenOwnerRecord: ProgramAccount<TokenOwnerRecord>,
client?: VotingClient
): Promise<PublicKey> => {
const instructions: TransactionInstruction[] = []
Expand All @@ -41,6 +42,7 @@ export const registerProgramGovernance = async (
//will run only if plugin is connected with realm
const plugin = await client?.withUpdateVoterWeightRecord(
instructions,
tokenOwnerRecord,
'createGovernance'
)

Expand All @@ -55,7 +57,7 @@ export const registerProgramGovernance = async (
config,
transferAuthority!,
walletPubkey,
tokenOwnerRecord,
tokenOwnerRecord.pubkey,
walletPubkey,
governanceAuthority,
plugin?.voterWeightPk
Expand Down
2 changes: 1 addition & 1 deletion components/AssetsList/NewProgramForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const NewProgramForm = () => {
new PublicKey(form.programId),
governanceConfig,
form.transferAuthority,
tokenOwnerRecord!.pubkey,
tokenOwnerRecord!,
client
)
setIsLoading(false)
Expand Down
2 changes: 1 addition & 1 deletion components/TreasuryAccount/NewTreasuryAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const NewAccountForm = () => {
realm,
treasuryType?.value === SOL ? null : new PublicKey(form.mintAddress),
governanceConfig,
tokenOwnerRecord!.pubkey,
tokenOwnerRecord!,
client
)
setIsLoading(false)
Expand Down
2 changes: 1 addition & 1 deletion components/VoteCommentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const VoteCommentModal: FunctionComponent<VoteCommentModalProps> = ({
rpcContext,
realm!,
proposal!,
voterTokenRecord.pubkey,
voterTokenRecord,
vote,
msg,
client
Expand Down
6 changes: 5 additions & 1 deletion components/VotePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const VotePanel = () => {
const client = useVotePluginsClientStore(
(s) => s.state.currentRealmVotingClient
)
const [isLoading, setIsLoading] = useState(false)
const router = useRouter()
const { pk } = router.query
const {
Expand Down Expand Up @@ -89,6 +90,7 @@ const VotePanel = () => {
connection.endpoint
)
try {
setIsLoading(true)
const instructions: TransactionInstruction[] = []

if (
Expand Down Expand Up @@ -124,6 +126,7 @@ const VotePanel = () => {
} catch (ex) {
console.error("Can't relinquish vote", ex)
}
setIsLoading(false)
}

const handleShowVoteModal = (vote: YesNoVote) => {
Expand Down Expand Up @@ -187,10 +190,11 @@ const VotePanel = () => {
<div className="items-center justify-center flex w-full gap-5">
{isVoteCast && connected ? (
<SecondaryButton
isLoading={isLoading}
small
tooltipMessage={withdrawTooltipContent}
onClick={() => submitRelinquishVote()}
disabled={!isWithdrawEnabled}
disabled={!isWithdrawEnabled || isLoading}
>
{isVoting ? 'Withdraw' : 'Release Tokens'}
</SecondaryButton>
Expand Down
11 changes: 5 additions & 6 deletions components/chat/DiscussionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const DiscussionForm = () => {
const { proposal } = useWalletStore((s) => s.selectedProposal)
const { fetchChatMessages } = useWalletStore((s) => s.actions)
const { tokenType } = useWalletStore((s) => s.selectedProposal)
const commenterVoterTokenRecord =
tokenType === GoverningTokenType.Community
? ownTokenRecord
: ownCouncilTokenRecord

const submitComment = async () => {
setSubmitting(true)
Expand All @@ -53,7 +57,7 @@ const DiscussionForm = () => {
rpcContext,
realm!,
proposal!,
ownVoterWeight.getTokenRecord(),
commenterVoterTokenRecord!,
msg,
undefined,
client
Expand All @@ -73,11 +77,6 @@ const DiscussionForm = () => {
const postEnabled =
proposal && connected && ownVoterWeight.hasAnyWeight() && comment

const commenterVoterTokenRecord =
tokenType === GoverningTokenType.Community
? ownTokenRecord
: ownCouncilTokenRecord

const tooltipContent = !connected
? 'Connect your wallet to send a comment'
: !ownVoterWeight.hasAnyWeight()
Expand Down
2 changes: 1 addition & 1 deletion hooks/useCreateProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function useCreateProposal() {
rpcContext,
realm!,
selectedGovernance.pubkey,
ownTokenRecord!.pubkey,
ownTokenRecord!,
title,
description,
proposalMint,
Expand Down
10 changes: 8 additions & 2 deletions hooks/useRealm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,18 @@ export default function useRealm() {
realmCfgMaxOutstandingProposalCount

const currentPluginPk = config?.account?.communityVoterWeightAddin

//based on realm config it will provide proper tokenBalanceCardComponent
const isLockTokensMode =
currentPluginPk && vsrPluginsPks.includes(currentPluginPk?.toBase58())
const isNftMode =
currentPluginPk && nftPluginsPks.includes(currentPluginPk?.toBase58())
const ownVoterWeight = getVoterWeight(
currentPluginPk,
ownTokenRecord,
votingPower,
nftVotingPower,
ownCouncilTokenRecord
)

return {
realm,
realmInfo,
Expand All @@ -143,6 +146,9 @@ export default function useRealm() {
toManyCouncilOutstandingProposalsForUse,
toManyCommunityOutstandingProposalsForUser,
config,
currentPluginPk,
isLockTokensMode,
isNftMode,
}
}

Expand Down
Loading

1 comment on commit 646e4f9

@vercel
Copy link

@vercel vercel bot commented on 646e4f9 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.