feat: constrain active proposals per wallet

This commit is contained in:
Sebastian.Bor 2021-08-12 21:49:50 +02:00
parent b11588d442
commit 277d2cfbee
9 changed files with 24 additions and 3 deletions

View File

@ -26,6 +26,7 @@ export const castVote = async (
realm,
proposal.info.governance,
proposal.pubkey,
proposal.info.tokenOwnerRecord,
tokeOwnerRecord,
governanceAuthority,
proposal.info.governingTokenMint,

View File

@ -21,6 +21,7 @@ export const finalizeVote = async (
realm,
proposal.info.governance,
proposal.pubkey,
proposal.info.tokenOwnerRecord,
proposal.info.governingTokenMint,
);

View File

@ -298,6 +298,8 @@ export class TokenOwnerRecord {
totalVotesCount: number;
outstandingProposalCount: number;
reserved: Uint8Array;
governanceDelegate?: PublicKey;
@ -309,6 +311,7 @@ export class TokenOwnerRecord {
governingTokenDepositAmount: BN;
unrelinquishedVotesCount: number;
totalVotesCount: number;
outstandingProposalCount: number;
reserved: Uint8Array;
}) {
this.realm = args.realm;
@ -317,6 +320,7 @@ export class TokenOwnerRecord {
this.governingTokenDepositAmount = args.governingTokenDepositAmount;
this.unrelinquishedVotesCount = args.unrelinquishedVotesCount;
this.totalVotesCount = args.totalVotesCount;
this.outstandingProposalCount = args.outstandingProposalCount;
this.reserved = args.reserved;
}
}

View File

@ -76,6 +76,8 @@ export const GovernanceError: Record<number, string> = [
'Not supported mint max vote weight source', // MintMaxVoteWeightSourceNotSupported
'Invalid max vote weight supply fraction', // InvalidMaxVoteWeightSupplyFraction
"Owner doesn't have enough governing tokens to create Governance", // NotEnoughTokensToCreateGovernance
'Too many outstanding proposals', // TooManyOutstandingProposals
'All proposals must be finalized to withdraw governing tokens', // AllProposalsMustBeFinalisedToWithdrawGoverningTokens
];
export const TokenError: Record<number, string> = [

View File

@ -398,7 +398,8 @@ export const GOVERNANCE_SCHEMA = new Map<any, any>([
['governingTokenDepositAmount', 'u64'],
['unrelinquishedVotesCount', 'u32'],
['totalVotesCount', 'u32'],
['reserved', [8]],
['outstandingProposalCount', 'u8'],
['reserved', [7]],
['governanceDelegate', { kind: 'option', type: 'pubkey' }],
],
},

View File

@ -25,7 +25,7 @@ export const withCancelProposal = (
},
{
pubkey: tokenOwnerRecord,
isWritable: false,
isWritable: true,
isSigner: false,
},
{

View File

@ -16,6 +16,7 @@ export const withCastVote = async (
realm: PublicKey,
governance: PublicKey,
proposal: PublicKey,
proposalOwnerRecord: PublicKey,
tokenOwnerRecord: PublicKey,
governanceAuthority: PublicKey,
governingTokenMint: PublicKey,
@ -49,6 +50,11 @@ export const withCastVote = async (
isWritable: true,
isSigner: false,
},
{
pubkey: proposalOwnerRecord,
isWritable: true,
isSigner: false,
},
{
pubkey: tokenOwnerRecord,
isWritable: true,

View File

@ -63,7 +63,7 @@ export const withCreateProposal = async (
},
{
pubkey: tokenOwnerRecord,
isWritable: false,
isWritable: true,
isSigner: false,
},
{

View File

@ -13,6 +13,7 @@ export const withFinalizeVote = async (
realm: PublicKey,
governance: PublicKey,
proposal: PublicKey,
proposalOwnerRecord: PublicKey,
governingTokenMint: PublicKey,
) => {
const args = new FinalizeVoteArgs();
@ -34,6 +35,11 @@ export const withFinalizeVote = async (
isWritable: true,
isSigner: false,
},
{
pubkey: proposalOwnerRecord,
isWritable: true,
isSigner: false,
},
{
pubkey: governingTokenMint,
isWritable: false,