-
Notifications
You must be signed in to change notification settings - Fork 22
/
vesting.ts
173 lines (162 loc) · 4.73 KB
/
vesting.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
import { Vest } from './contracts/CwVesting'
import { GenericToken } from './token'
export enum VestingContractVersion {
/**
* Version 1 supports vesting payment owner different from factory owner.
*/
V1 = 1,
/**
* Version 2 fixes a bug that prevented vesting NTRN on Neutron.
*/
V2 = 2,
}
/**
* The latest version of the vesting contract used by the vesting payments
* widget.
*/
export const LATEST_VESTING_CONTRACT_VERSION = VestingContractVersion.V2
export type VestingPaymentsWidgetData = {
/**
* A map of chain ID to current factory on that chain. This replaces the
* single `factory` and allows for multiple chains. Old versions should be
* added to the `oldFactories` list.
*/
factories?: Record<
string,
{
address: string
version: VestingContractVersion
}
>
/**
* Pre-interchain vesting used this field as the only factory. The factories
* array above is now used instead and takes precedence. This factory, if
* defined, is on the same chain as the DAO.
*/
factory?: string
/**
* Versioning was created after the widget was created, so it may be
* undefined. If undefined, assume it supports none of the versioned features.
* This is part of the old single factory, before the factories map which
* allows for multiple chains.
*/
version?: VestingContractVersion
/**
* In case the vesting factory is updated, keep a list of the old factories so
* we still show their vesting payments.
*/
oldFactories?: OldVestingPaymentFactory[]
}
export type OldVestingPaymentFactory = {
/**
* Chain ID was added later. If undefined, assume it is the same as the DAO.
*/
chainId?: string
address: string
/**
* Versioning was created after the widget was created, so it may be
* undefined. If undefined, assume it supports none of the versioned features.
*/
version?: VestingContractVersion
}
export type VestingValidatorSlash = {
// The time the slash occurred.
timeMs: number
// The amount that got slashed.
amount: number
// The amount of the slash that has not been registered with the contract.
// This should be equal to `amount` if the slash has not been registered and 0
// otherwise. If between 0 and the slash amount, then only part of the slash
// has been registered, and this is the unregistered portion. This should only
// happen if multiple slashes occurred at the same time and only some of them
// have been registered (which I do not think is possible) or if someone
// somehow registered only part of a slash (likely manually or due to a UI
// bug).
unregisteredAmount: number
// Whether or not this slash was of tokens currently unbonding.
duringUnbonding: boolean
}
export type VestingValidatorWithSlashes = {
validatorOperatorAddress: string
slashes: VestingValidatorSlash[]
}
export type VestingInfo = {
chainId: string
vestingContractAddress: string
vest: Vest
token: GenericToken
owner:
| ({
address: string
} & (
| {
// Whether or not the owner is a cw1-whitelist contract.
isCw1Whitelist: true
// The list of admins whitelisted by the contract.
cw1WhitelistAdmins: string[]
}
| {
isCw1Whitelist: false
cw1WhitelistAdmins?: undefined
}
))
| undefined
// Amount vested so far.
vested: string
// Amount available to distribute.
distributable: string
// Total amount being vested.
total: string
// The stakable balance. This is the unstaked amount still in the vesting
// contract. It may be vested or not, but it is definitely not claimed nor
// staked.
stakable: string
// Slashes on staked or unstaked tokens that have occurred during the vest.
slashes: VestingValidatorWithSlashes[]
// Whether or not all slashes have been registered.
hasUnregisteredSlashes: boolean
// Whether or not all has been claimed.
completed: boolean
// Dates.
startDate: Date
endDate: Date
// Steps.
steps: VestingStep[]
}
export type VestingStep = {
timestamp: number
// Total amount vested at this timestamp.
amount: number
}
export type CwVestingStakeEvent = {
blockHeight: string
blockTimeUnixMs: string
} & (
| {
type: 'delegate'
validator: string
amount: string
}
| {
type: 'undelegate'
validator: string
amount: string
}
| {
type: 'redelegate'
fromValidator: string
toValidator: string
amount: string
}
)
export type CwVestingSlashRegistration = {
validator: string
// Nanoseconds.
time: string
amount: string
duringUnbonding: boolean
}
export type CwVestingStakeHistory = {
stakeEvents: CwVestingStakeEvent[]
slashRegistrations: CwVestingSlashRegistration[]
}