forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gov.ts
191 lines (172 loc) · 5.04 KB
/
gov.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { ReactNode } from 'react'
import { CommunityPoolSpendProposal } from '@dao-dao/utils/protobuf/codegen/cosmos/distribution/v1beta1/distribution'
import {
Params as GovParamsV1,
Proposal as ProposalV1,
WeightedVoteOption,
} from '@dao-dao/utils/protobuf/codegen/cosmos/gov/v1/gov'
import {
Proposal as ProposalV1Beta1,
TextProposal,
} from '@dao-dao/utils/protobuf/codegen/cosmos/gov/v1beta1/gov'
import { ParameterChangeProposal } from '@dao-dao/utils/protobuf/codegen/cosmos/params/v1beta1/params'
import {
CancelSoftwareUpgradeProposal,
SoftwareUpgradeProposal,
} from '@dao-dao/utils/protobuf/codegen/cosmos/upgrade/v1beta1/upgrade'
import { NestedActionsEditorFormData } from './actions'
import { LoadingData } from './components'
import { Coin, CosmosMsgFor_Empty } from './contracts'
import { ProcessedTQ } from './utils'
export { ProposalV1Beta1, ProposalV1 }
export enum GovProposalVersion {
// Legacy with specific proposal types.
V1_BETA_1 = 'v1beta1',
// Arbitrary message execution.
V1 = 'v1',
}
export type GovProposalV1Beta1 = {
version: GovProposalVersion.V1_BETA_1
id: bigint
proposal: ProposalV1Beta1
}
export type GovProposalV1Beta1DecodedContent = ProposalV1Beta1['content']
export type GovProposalV1Beta1WithDecodedContent = GovProposalV1Beta1 & {
title: string
description: string
decodedContent: GovProposalV1Beta1DecodedContent
}
export type GovProposalV1 = {
version: GovProposalVersion.V1
id: bigint
proposal: ProposalV1
}
export type GovProposalV1DecodedMessages = CosmosMsgFor_Empty[]
export type GovProposalV1WithDecodedMessages = GovProposalV1 & {
title: string
description: string
decodedMessages: GovProposalV1DecodedMessages
legacyContent: GovProposalV1Beta1DecodedContent[]
}
export type GovProposalDecodedContent =
| {
version: GovProposalVersion.V1_BETA_1
title: string
description: string
decodedContent: GovProposalV1Beta1DecodedContent
}
| {
version: GovProposalVersion.V1
title: string
description: string
decodedMessages: GovProposalV1DecodedMessages
legacyContent: GovProposalV1Beta1DecodedContent[]
}
export type GovProposal = GovProposalV1Beta1 | GovProposalV1
export type GovProposalWithDecodedContent =
| GovProposalV1Beta1WithDecodedContent
| GovProposalV1WithDecodedMessages
export type GovProposalWithMetadata = GovProposal & {
timestampInfo: ProposalTimestampInfo
votesInfo: GovProposalVotesInfo
walletVoteInfo: LoadingData<GovProposalWalletVoteInfo>
// Deposit needed to ender voting period.
minDeposit: Coin[]
}
export type ProposalTimestampInfo = {
display?: {
label: string
tooltip?: string
content: ReactNode
}
expirationDate: Date
}
export type GovProposalVotesInfo = {
threshold: ProcessedTQ
quorum: ProcessedTQ
vetoThreshold: ProcessedTQ
// Raw info
yesVotes: number
noVotes: number
abstainVotes: number
noWithVetoVotes: number
totalVotingPower: number
turnoutTotal: number
// Turnout percents
turnoutPercent: number
turnoutYesPercent: number
turnoutNoPercent: number
turnoutAbstainPercent: number
turnoutNoWithVetoPercent: number
// Total percents
totalYesPercent: number
totalNoPercent: number
totalAbstainPercent: number
totalNoWithVetoPercent: number
// Meta
thresholdReached: boolean
quorumReached: boolean
vetoReached: boolean
}
export type GovProposalWalletVoteInfo = {
// Present if voted.
vote: WeightedVoteOption[] | undefined
}
export type GovProposalActionDisplayProps = {
content: GovProposalDecodedContent
// Passed on to action renderer.
hideCopyLink?: boolean
}
export type AllGovParams = Pick<
GovParamsV1,
'minDeposit' | 'maxDepositPeriod' | 'votingPeriod'
> & {
quorum: number
threshold: number
vetoThreshold: number
minInitialDepositRatio: number
}
export const GOVERNANCE_PROPOSAL_TYPES = [
TextProposal,
CommunityPoolSpendProposal,
ParameterChangeProposal,
SoftwareUpgradeProposal,
CancelSoftwareUpgradeProposal,
]
export const GOVERNANCE_PROPOSAL_TYPE_CUSTOM = 'CUSTOM'
export type GovernanceProposalActionData = {
chainId: string
// The address of the chain's gov module. Loaded in the background.
govModuleAddress?: string
// If true, will hide title, description, and deposit.
_onlyShowActions?: boolean
version: GovProposalVersion
title: string
description: string
deposit: {
amount: number
denom: string
}[]
legacy: {
typeUrl: string
// CommunityPoolSpendProposal
spends: {
amount: number
denom: string
}[]
spendRecipient: string
// ParameterChangeProposal
parameterChanges: string
// SoftwareUpgradeProposal
upgradePlan: string
// CUSTOM
custom: string
}
// One of the legacy proposal types encoded into its protobuf. Outside the
// legacy object so we can listen for changes to it to update this field
// without causing infinite loops.
// GovProposalV1Beta1DecodedContent
legacyContent: any
// V1 proposals require a metadata.json file to be uploaded to IPFS.
metadataCid: string
} & NestedActionsEditorFormData