-
Notifications
You must be signed in to change notification settings - Fork 17
/
BlockSpecialEvents.ts
161 lines (150 loc) · 5.53 KB
/
BlockSpecialEvents.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
import type { BakerId } from '../types.js';
import * as CcdAmount from './CcdAmount.js';
import * as AccountAddress from './AccountAddress.js';
export type BlockSpecialEvent =
| BlockSpecialEventBakingRewards
| BlockSpecialEventMint
| BlockSpecialEventFinalizationRewards
| BlockSpecialEventBlockReward
| BlockSpecialEventPaydayFoundationReward
| BlockSpecialEventPaydayAccountReward
| BlockSpecialEventBlockAccrueReward
| BlockSpecialEventPaydayPoolReward;
export interface BlockSpecialEventBakingRewards {
tag: 'bakingRewards';
// The amount awarded to each baker.
bakingRewards: BlockSpecialEventAccountAmount[];
// The remaining balance of the baker reward account.
remainder: CcdAmount.Type;
}
export interface BlockSpecialEventMint {
tag: 'mint';
// The amount allocated to the banking reward account.
mintBakingReward: CcdAmount.Type;
// The amount allocated to the finalization reward account.
mintFinalizationReward: CcdAmount.Type;
// The amount allocated as the platform development charge.
mintPlatformDevelopmentCharge: CcdAmount.Type;
// The account to which the platform development charge is paid.
foundationAccount: AccountAddress.Type;
}
export interface BlockSpecialEventFinalizationRewards {
tag: 'finalizationRewards';
// The amount awarded to each finalizer.
finalizationRewards?: BlockSpecialEventAccountAmount[];
// The remaining balance of the finalization reward account.
remainder?: CcdAmount.Type;
}
export interface BlockSpecialEventBlockReward {
tag: 'blockReward';
// The total fees paid for transactions in the block.
transactionFees: CcdAmount.Type;
// The old balance of the GAS account.
oldGasAccount: CcdAmount.Type;
// The new balance of the GAS account.
newGasAccount: CcdAmount.Type;
// The amount awarded to the baker.
bakerReward: CcdAmount.Type;
// The amount awarded to the foundation.
foundationCharge: CcdAmount.Type;
// The baker of the block, who receives the award.
baker: AccountAddress.Type;
// The foundation account.
foundationAccount: AccountAddress.Type;
}
export interface BlockSpecialEventPaydayFoundationReward {
tag: 'paydayFoundationReward';
// The account that got rewarded.
foundationAccount: AccountAddress.Type;
// The transaction fee reward at payday to the account.
developmentCharge: CcdAmount.Type;
}
export interface BlockSpecialEventPaydayAccountReward {
tag: 'paydayAccountReward';
// The account that got rewarded.
account: AccountAddress.Type;
// The transaction fee reward at payday to the account.
transactionFees: CcdAmount.Type;
// The baking reward at payday to the account.
bakerReward: CcdAmount.Type;
// The finalization reward at payday to the account.
finalizationReward: CcdAmount.Type;
}
export interface BlockSpecialEventBlockAccrueReward {
tag: 'blockAccrueReward';
// The total fees paid for transactions in the block.
transactionFees: CcdAmount.Type;
// The old balance of the GAS account.
oldGasAccount: CcdAmount.Type;
// The new balance of the GAS account.
newGasAccount: CcdAmount.Type;
// The amount awarded to the baker.
bakerReward: CcdAmount.Type;
// The amount awarded to the passive delegators.
passiveReward: CcdAmount.Type;
// The amount awarded to the foundation.
foundationCharge: CcdAmount.Type;
// The baker of the block, who will receive the award.
baker: BakerId;
}
export interface BlockSpecialEventPaydayPoolReward {
tag: 'paydayPoolReward';
// The pool owner (passive delegators when not present).
poolOwner?: BakerId;
// Accrued transaction fees for pool.
transactionFees: CcdAmount.Type;
// Accrued baking rewards for pool.
bakerReward: CcdAmount.Type;
// Accrued finalization rewards for pool.
finalizationReward: CcdAmount.Type;
}
export interface BlockSpecialEventAccountAmount {
// The key type
account: AccountAddress.Type;
// The value type
amount: CcdAmount.Type;
}
/**
* Gets a list of {@link AccountAddress.Type} account addresses affected the {@link BlockSpecialEvent}.
*
* @param {BlockSpecialEvent} event - The block special event to check.
*
* @returns {AccountAddress.Type[]} List of account addresses affected by the event.
*/
export function specialEventAffectedAccounts(
event: Exclude<
BlockSpecialEvent,
BlockSpecialEventBlockAccrueReward | BlockSpecialEventPaydayPoolReward
>
): AccountAddress.Type[];
export function specialEventAffectedAccounts(
event:
| BlockSpecialEventBlockAccrueReward
| BlockSpecialEventPaydayPoolReward
): never[];
export function specialEventAffectedAccounts(
event: BlockSpecialEvent
): AccountAddress.Type[];
export function specialEventAffectedAccounts(
event: BlockSpecialEvent
): AccountAddress.Type[] {
switch (event.tag) {
case 'bakingRewards':
return event.bakingRewards.map((br) => br.account);
case 'finalizationRewards':
return event.finalizationRewards?.map((fr) => fr.account) ?? [];
case 'mint':
case 'paydayFoundationReward':
return [event.foundationAccount];
case 'paydayAccountReward':
return [event.account];
case 'blockReward': {
if (AccountAddress.equals(event.baker, event.foundationAccount)) {
return [event.baker];
}
return [event.baker, event.foundationAccount];
}
default:
return [];
}
}