-
Notifications
You must be signed in to change notification settings - Fork 22
/
chain.ts
374 lines (346 loc) · 9.61 KB
/
chain.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import { Chain } from '@chain-registry/types'
import { HugeDecimal } from '@dao-dao/math'
import { Coin } from './contracts'
import { ContractVersion } from './features'
import { SkipChain } from './skip'
import { GenericToken, TokenType } from './token'
export type AnyChain = {
chainId: string
chainName: string
bech32Prefix: string
prettyName: string
/**
* Chain registry definition if exists.
*/
chainRegistry?: Chain
/**
* Skip chain definition if fetched via Skip API.
*/
skipChain?: SkipChain
}
export type IChainContext = {
chainId: string
chain: AnyChain
// Chain may not have a native token.
nativeToken?: GenericToken
// If defined, this is a configured chain, which means it is supported (DAO
// DAO is deployed on it) or it has a governance interface.
base?: BaseChainConfig
// If defined, this is a supported chain, which means DAO DAO is deployed.
config?: SupportedChainConfig
}
// Require base chain config.
export type ConfiguredChainContext = Omit<IChainContext, 'base' | 'config'> & {
config: BaseChainConfig
}
// Require supported chain config.
export type SupportedChainContext = Omit<ConfiguredChainContext, 'config'> & {
config: SupportedChainConfig
}
export type Validator = {
address: string
moniker: string
website: string
details: string
commission: number
status: string
tokens: HugeDecimal
}
export type Delegation = {
validator: Validator
delegated: Coin
pendingReward: Coin
}
export type UnbondingDelegation = {
validator: Validator
balance: Coin
startedAtHeight: number
finishesAt: Date
}
export type NativeDelegationInfo = {
delegations: Delegation[]
unbondingDelegations: UnbondingDelegation[]
}
export enum ChainId {
CosmosHubMainnet = 'cosmoshub-4',
CosmosHubProviderTestnet = 'provider',
JunoMainnet = 'juno-1',
JunoTestnet = 'uni-6',
OsmosisMainnet = 'osmosis-1',
OsmosisTestnet = 'osmo-test-5',
StargazeMainnet = 'stargaze-1',
StargazeTestnet = 'elgafar-1',
NeutronMainnet = 'neutron-1',
NeutronTestnet = 'pion-1',
TerraMainnet = 'phoenix-1',
TerraClassicMainnet = 'columbus-5',
MigalooMainnet = 'migaloo-1',
MigalooTestnet = 'narwhal-2',
NobleMainnet = 'noble-1',
KujiraMainnet = 'kaiyo-1',
KujiraTestnet = 'harpoon-4',
ChihuahuaMainnet = 'chihuahua-1',
OraichainMainnet = 'Oraichain',
ArchwayMainnet = 'archway-1',
InjectiveMainnet = 'injective-1',
BitsongMainnet = 'bitsong-2b',
BitsongTestnet = 'bobnet',
OmniflixHubMainnet = 'omniflixhub-1',
OmniflixHubTestnet = 'flixnet-4',
SecretMainnet = 'secret-4',
SecretTestnet = 'pulsar-3',
}
export type BaseChainConfig = {
/**
* Chain ID.
*/
chainId: string
/**
* Unique name among chain configs with the same `mainnet` flag. This is used
* to identify the chain in the native governance UI.
*/
name: string
/**
* Whether or not this should be shown on the mainnet UI. If not, it will be
* shown in the testnet UI.
*/
mainnet: boolean
/**
* An accent color for using in the UI.
*/
accentColor: string
/**
* Set to true if the chain does not support CosmWasm. If undefined, assumed
* to be false.
*/
noCosmWasm?: boolean
/**
* Set to true if the chain does not have a gov module so that it doesn't
* appear in the gov UI. If undefined, assumed to be false.
*/
noGov?: boolean
/**
* Chain explorer URL templates for various external links.
*/
explorerUrlTemplates?: {
tx?: string
gov?: string
govProp?: string
wallet?: string
}
/**
* If defined, overrides the default chain image.
*/
overrideChainImageUrl?: string
}
export type ConfiguredChain = BaseChainConfig & {
/**
* Chain info.
*/
chain: AnyChain
}
export type SupportedChainConfig = Omit<BaseChainConfig, 'chainId'> & {
/**
* Chain ID.
*/
chainId: ChainId
/**
* The `cw-admin-factory` contract address that instantiates contracts with
* themselves set as their admin.
* https://github.com/DA0-DA0/dao-contracts/tree/development/contracts/external/cw-admin-factory
*/
factoryContractAddress: string
/**
* If defined, it means Kado supports fiat deposit on this chain.
*/
kado?: {
/**
* The Kado network identifier.
*/
network: string
}
/**
* Map DAO creator ID to whether or not it's disabled and for what reason. If
* not present, enabled.
*/
daoCreatorDisabled?: Partial<
Record<string, 'underDevelopment' | 'unsupported'>
>
/**
* Active (latest) version of the code IDs.
*/
latestVersion: ContractVersion
/**
* Active (latest) code IDs.
*/
codeIds: CodeIdConfig
/**
* All deployed versions of the code IDs on this chain.
*/
allCodeIds: Partial<Record<ContractVersion, Partial<CodeIdConfig>>>
/**
* Active (latest) code hashes. Only used by Secret Network.
*/
codeHashes?: CodeHashConfig
/**
* All deployed versions of the code hashes on this chain.
*/
allCodeHashes?: Partial<Record<ContractVersion, Partial<CodeHashConfig>>>
/**
* Whether to create token DAOs with native tokens (including tokenfactory),
* CW20s, or both. Defaults to native tokens.
*/
tokenDaoType?: TokenType.Native | TokenType.Cw20 | 'both'
/**
* Disallow creating new tokens for token-based DAOs and show a tooltip that
* token creation is under development. Defaults to false.
*/
tokenCreationUnderDevelopment?: boolean
/**
* Disallow creating new tokens for token-based DAOs and show a tooltip that
* token creation is disabled due to the lack of token factory. Defaults to
* false.
*/
noTokenFactory?: boolean
/**
* Token creation factory address to use during DAO creation.
*/
tokenCreationFactoryAddress?: string
/**
* Whether or not to create a DAO through chain governance.
*/
createViaGovernance?: boolean
/**
* Whether or not this chain supports instantiate2 for creating DAOs with
* extensions setup.
*/
noInstantiate2Create?: boolean
/**
* Whether or not this chain has an indexer.
*/
noIndexer?: boolean
/**
* If this chain uses a DAO as its chain governance instead of x/gov, set this
* to the DAO's address.
*/
govContractAddress?: string
/**
* SubDAOs to display with this chain's native governance.
*
* These should be legitimate SubDAOs with the chain governance module set as
* their admin. This is necessray because chains cannot recognize SubDAOs as
* they are not DAO contracts, and we need to establish which SubDAOs of a DAO
* are legitimate for safety.
*/
subDaos?: string[]
/**
* Polytone connections to other chains from this chain.
*/
polytone?: PolytoneConfig
/**
* Timewave's Valence config.
*/
valence?: {
/**
* Address of services manager contract.
*/
servicesManager: string
/**
* Address of rebalancer contract.
*/
rebalancer: string
}
}
export type SupportedChain = SupportedChainConfig & {
chain: AnyChain
}
export type CodeIdConfig = {
// https://github.com/CosmWasm/cw-plus
Cw1Whitelist: number
Cw4Group: number
// https://github.com/CosmWasm/cw-nfts
Cw721Base?: number
// https://github.com/DA0-DA0/dao-contracts
CwPayrollFactory: number
CwTokenSwap: number
CwTokenfactoryIssuer: number
CwVesting: number
DaoDaoCore: number
DaoMigrator?: number
DaoPreProposeApprovalSingle: number
DaoPreProposeApprover: number
DaoPreProposeMultiple: number
DaoPreProposeSingle: number
DaoProposalMultiple: number
DaoProposalSingle: number
DaoRewardsDistributor: number
DaoVotingCw4: number
DaoVotingCw721Staked: number
DaoVotingTokenStaked: number
// For Secret Network
QueryAuth?: number
// For OmniFlix
DaoVotingOnftStaked?: number
// For migrating v1 to v2 DAOs, and some chains use CW20s.
Cw20Base?: number
Cw20Stake?: number
DaoVotingCw20Staked?: number
// Valence
ValenceAccount?: number
}
export type CodeHashConfig = {
[K in keyof CodeIdConfig]: string
}
export type PolytoneConnection = {
// Contract address of note on the local/current chain.
note: string
// Contract address of the note's listener on the local/current chain.
listener: string
// Contract address of the note's voice on the remote chain.
voice: string
// IBC connection IDs
localConnection: string
remoteConnection: string
// IBC channel IDs
localChannel: string
remoteChannel: string
// Whether or not the user needs to self-relay an execution. This should be
// true if no relayers are running on the established connection. If using an
// existing active connection, the relayers will automatically perform the
// relay.
needsSelfRelay?: boolean
}
// Map chain ID to polytone connection information.
export type PolytoneConfig = Record<string, PolytoneConnection>
export type WithChainId<T> = T & {
chainId: string
}
export type DecodedStargateMsg<Value = any> = {
stargate: {
typeUrl: string
value: Value
}
}
/**
* Function that creates a cw1-whitelist contract. Used in the
* `useCreateCw1Whitelist` hook.
*/
export type CreateCw1Whitelist = (
admins: string[],
mutable?: boolean
) => Promise<string | undefined>
export type ValidatorSlash = {
registeredBlockHeight: string
registeredBlockTimeUnixMs: string
infractionBlockHeight: string
// Slash fraction applied to validator's undelegating and redelegating tokens.
slashFactor: string
amountSlashed: string
// Slash fraction applied to validator's current delegations. It may be less
// than `slashFactor`.
effectiveFraction: string
// Amount of tokens slashed from delegations. This should be `amountSlashed`
// minus the amount slashed from the validator's undelegating and redelegating
// tokens.
stakedTokensBurned: string
}