-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathuseGovernanceDefaults.ts
More file actions
108 lines (93 loc) · 3.32 KB
/
useGovernanceDefaults.ts
File metadata and controls
108 lines (93 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { GovernanceConfig, VoteThresholdType } from '@solana/spl-governance';
import { PublicKey } from '@solana/web3.js';
import BigNumber from 'bignumber.js';
import BN from 'bn.js';
import { pipe } from 'fp-ts/lib/function';
import { Rules } from '../EditWalletRules/types';
import useTreasuryInfo from '@hooks/useTreasuryInfo';
import { GovernanceTokenType } from '@hub/types/GovernanceTokenType';
import { GovernanceVoteTipping } from '@hub/types/GovernanceVoteTipping';
import * as RE from '@hub/types/Result';
import { DISABLED_VOTER_WEIGHT } from '@tools/constants';
const configs2defaults = (configs: GovernanceConfig[]) => {
// community ---
const enableCommunityVote =
configs.find(
(x) => x.communityVoteThreshold.type !== VoteThresholdType.Disabled,
) !== undefined;
const highestMinCommunityTokensToCreateProposal = configs.reduce(
(acc, x) => BN.max(acc, x.minCommunityTokensToCreateProposal),
new BN(0),
);
// council ---
const enableCouncilVote =
configs.find(
(x) => x.councilVoteThreshold.type !== VoteThresholdType.Disabled,
) !== undefined;
const enableCouncilVetoVote =
configs.find(
(x) => x.councilVetoVoteThreshold.type !== VoteThresholdType.Disabled,
) !== undefined;
const highestMinCouncilTokensToCreateProposal = configs.reduce(
(acc, x) => BN.max(acc, x.minCouncilTokensToCreateProposal),
new BN(0),
);
const x: Omit<Rules, 'governanceAddress' | 'walletAddress'> = {
communityTokenRules: {
tokenMintAddress: PublicKey.default,
canCreateProposal:
enableCommunityVote &&
!highestMinCommunityTokensToCreateProposal.eq(DISABLED_VOTER_WEIGHT),
votingPowerToCreateProposals: new BigNumber(
highestMinCommunityTokensToCreateProposal.toString(),
),
tokenType: GovernanceTokenType.Community,
canVeto: false,
vetoQuorumPercent: 60,
canVote: enableCommunityVote,
quorumPercent: 60,
voteTipping: GovernanceVoteTipping.Disabled,
},
councilTokenRules: {
tokenMintAddress: PublicKey.default,
canCreateProposal:
enableCouncilVote &&
!highestMinCouncilTokensToCreateProposal.eq(DISABLED_VOTER_WEIGHT),
votingPowerToCreateProposals: new BigNumber(
highestMinCouncilTokensToCreateProposal.toString(),
),
tokenType: GovernanceTokenType.Council,
canVeto: enableCouncilVetoVote,
vetoQuorumPercent: 60,
canVote: enableCouncilVote,
quorumPercent: 60,
voteTipping: GovernanceVoteTipping.Disabled,
},
coolOffHours: 12,
maxVoteDays: 3,
depositExemptProposalCount: 10,
minInstructionHoldupDays: 0,
governanceSeed: "",
version: 3,
};
return x;
};
const useGovernanceDefaults = ():
| undefined
| Omit<Rules, 'governanceAddress' | 'walletAddress'> => {
const data = useTreasuryInfo(false);
const configs = pipe(
data,
RE.match(
() => undefined,
() => undefined,
(y) => y.wallets.map((x) => x.governanceAccount?.account.config),
),
);
const defaults =
configs !== undefined && !configs.find((x) => x === undefined) // I assume undefined means loading
? configs2defaults(configs as GovernanceConfig[]) // look typescript i PROMISE there's not any undefined members
: undefined;
return defaults;
};
export default useGovernanceDefaults;