forked from Uniswap/sybil-interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducer.ts
194 lines (175 loc) · 6.13 KB
/
reducer.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
import { DelegateData } from './hooks'
import { SerializedToken } from './../user/actions'
import { ChainId, Token } from '@uniswap/sdk'
import {
updateActiveProtocol,
updateFilterActive,
updateTopDelegates,
updateVerifiedDelegates,
updateGlobalData,
updateMaxFetched,
} from './actions'
import { createReducer } from '@reduxjs/toolkit'
import UniLogo from '../../assets/images/uni-logo.png'
import CompLogo from '../../assets/images/compLogo.png'
import AaveLogo from '../../assets/images/aave-logo.png'
import PoolLogo from '../../assets/images/pooltogether-icon.png'
import RadicleLogo from '../../assets/images/radicle-logo.svg'
import { serializeToken } from '../user/hooks'
export interface GovernanceInfo {
id: string
name: string
logo: string
primaryColor: string
secondaryColor: string
token: SerializedToken
governanceAlphaAddresses: string[]
governanceAddressBravo?: string
migrationProposalId?: number
social: string
emoji?: string
}
// protocol wide data
export interface GlobaData {
id: string
totalTokenHolders: number
totalDelegates: number
delegatedVotes: number
delegatedVotesRaw: number
}
// constant addresses for supported protocols
export const UNI_GOVERNANCE_ADDRESS = '0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F'
export const UNI_GOVERNANCE_ADDRESS_BRAVO = '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6'
export const UNI_ADDRESS = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'
const UNI = new Token(ChainId.MAINNET, UNI_ADDRESS, 18, 'UNI', 'Uniswap')
export const UNISWAP_GOVERNANCE: GovernanceInfo = {
id: 'uniswap',
name: 'Uniswap Governance',
logo: UniLogo,
primaryColor: '#FF007A',
secondaryColor: '#FDEEF5',
token: serializeToken(UNI),
governanceAlphaAddresses: [UNI_GOVERNANCE_ADDRESS, UNI_GOVERNANCE_ADDRESS_BRAVO],
migrationProposalId: 5,
social: '@UniswapProtocol',
emoji: '🦄',
}
export const COMP_GOVERNANCE_ADDRESS_BRAVO = '0xc0da02939e1441f497fd74f78ce7decb17b66529'
export const COMP_GOVERNANCE_ADDRESS = '0xc0dA01a04C3f3E0be433606045bB7017A7323E38'
export const COMP_ADDRESS = '0xc00e94cb662c3520282e6f5717214004a7f26888'
const COMP = new Token(ChainId.MAINNET, COMP_ADDRESS, 18, 'COMP', 'Compound Governance Token')
export const COMPOUND_GOVERNANCE: GovernanceInfo = {
id: 'compound',
name: 'Compound Governance',
logo: CompLogo,
primaryColor: '#00D395',
secondaryColor: '#E1F9F1',
token: serializeToken(COMP),
governanceAlphaAddresses: [COMP_GOVERNANCE_ADDRESS],
governanceAddressBravo: COMP_GOVERNANCE_ADDRESS_BRAVO,
migrationProposalId: 42,
social: '@compoundfinance',
emoji: '🏦',
}
export const AAVE_GOVERNANCE_ADDRESS = '0xEC568fffba86c094cf06b22134B23074DFE2252c'
export const AAVE_ADDRESS = '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'
const AAVE = new Token(ChainId.MAINNET, AAVE_ADDRESS, 18, 'AAVE', 'Aave Token')
export const AAVE_GOVERNANCE: GovernanceInfo = {
id: 'aave',
name: 'Aave Governance',
logo: AaveLogo,
primaryColor: '#B6509E',
secondaryColor: '#ebfeff',
token: serializeToken(AAVE),
governanceAlphaAddresses: [AAVE_GOVERNANCE_ADDRESS],
social: '@AaveAave',
emoji: '👻',
}
export const POOL_TOGETHER_GOVERNANCE_ADDRESS = '0xB3a87172F555ae2a2AB79Be60B336D2F7D0187f0'
export const POOL_ADDRESS = '0x0cEC1A9154Ff802e7934Fc916Ed7Ca50bDE6844e'
const POOL = new Token(ChainId.MAINNET, POOL_ADDRESS, 18, 'POOL', 'PoolTogether')
export const POOL_TOGETHER_GOVERNANCE: GovernanceInfo = {
id: 'pool',
name: 'PoolTogether Governance',
logo: PoolLogo,
primaryColor: '#5c0ef3',
secondaryColor: '#f2eeff',
token: serializeToken(POOL),
governanceAlphaAddresses: [POOL_TOGETHER_GOVERNANCE_ADDRESS],
social: '@PoolTogether_',
emoji: '🏆',
}
export const RADICLE_GOVERNANCE_ADDRESS = '0x690e775361AD66D1c4A25d89da9fCd639F5198eD'
export const RADICLE_ADDRESS = '0x31c8EAcBFFdD875c74b94b077895Bd78CF1E64A3'
const RADICLE = new Token(ChainId.MAINNET, RADICLE_ADDRESS, 18, 'RAD', 'Radicle')
export const RADICLE_GOVERNANCE: GovernanceInfo = {
id: 'radicle',
name: 'Radicle Governance',
logo: RadicleLogo,
primaryColor: '#5555FF',
secondaryColor: '#E3E3FF',
token: serializeToken(RADICLE),
governanceAlphaAddresses: [RADICLE_GOVERNANCE_ADDRESS],
social: '@radicle',
emoji: '🌱',
}
// mapping for routing
export const SUPPORTED_PROTOCOLS: { [id: string]: GovernanceInfo } = {
uniswap: UNISWAP_GOVERNANCE,
compound: COMPOUND_GOVERNANCE,
aave: AAVE_GOVERNANCE,
pool: POOL_TOGETHER_GOVERNANCE,
radicle: RADICLE_GOVERNANCE,
}
export const FETCHING_INTERVAL = 50
export interface GovernanceState {
// the selected option from supported protocol options
activeProtocol: GovernanceInfo | undefined
// filter only verified delegates
filterActive: boolean
// top delegates based on votes
topDelegates: {
[protocolID: string]: DelegateData[] | undefined
}
// used for paginated delegate lookup
maxFetched: {
[protocolID: string]: number | undefined
}
// only delegates with verified usernames
verifiedDelegates: {
[protocolID: string]: DelegateData[] | undefined
}
globalData: {
[protocolID: string]: GlobaData | undefined
}
}
export const initialState: GovernanceState = {
activeProtocol: undefined,
filterActive: false,
// top delegates and pagination details
topDelegates: {},
maxFetched: {},
verifiedDelegates: {},
globalData: {},
}
export default createReducer(initialState, (builder) =>
builder
.addCase(updateActiveProtocol, (state, action) => {
state.activeProtocol = action.payload.activeProtocol
})
.addCase(updateFilterActive, (state, action) => {
state.filterActive = action.payload.filterActive
})
.addCase(updateTopDelegates, (state, action) => {
state.topDelegates[action.payload.protocolID] = action.payload.topDelegates
})
.addCase(updateVerifiedDelegates, (state, action) => {
state.verifiedDelegates[action.payload.protocolID] = action.payload.verifiedDelegates
})
.addCase(updateGlobalData, (state, action) => {
state.globalData[action.payload.protocolID] = action.payload.data
})
.addCase(updateMaxFetched, (state, action) => {
state.maxFetched[action.payload.protocolID] = action.payload.maxFetched
})
)