@@ -25,7 +25,7 @@ import { RetryBackoffConfig } from 'backoff-rxjs';
25
25
import { TrackedStakePoolProvider } from '../ProviderTracker' ;
26
26
import { TxWithEpoch } from './types' ;
27
27
import { coldObservableProvider } from '@cardano-sdk/util-rxjs' ;
28
- import { isLastStakeKeyCertOfType } from './transactionCertificates' ;
28
+ import { lastStakeKeyCertOfType } from './transactionCertificates' ;
29
29
import findLast from 'lodash/findLast' ;
30
30
import isEqual from 'lodash/isEqual' ;
31
31
import uniq from 'lodash/uniq' ;
@@ -124,15 +124,12 @@ export const createRewardsProvider =
124
124
) ;
125
125
export type ObservableRewardsProvider = ReturnType < typeof createRewardsProvider > ;
126
126
127
- const isDelegationCertificate = ( cert : Cardano . Certificate ) : cert is Cardano . StakeDelegationCertificateUnion =>
128
- Cardano . StakeDelegationCertificateTypes . includes ( cert . __typename as Cardano . StakeDelegationCertificateTypes ) ;
129
-
130
127
const getAccountsKeyStatus =
131
128
( addresses : Cardano . RewardAccount [ ] ) =>
132
129
( [ transactions , transactionsInFlight ] : [ TxWithEpoch [ ] , TxInFlight [ ] ] ) => {
133
130
const certificatesInFlight = transactionsInFlight . map ( ( { body : { certificates } } ) => certificates || [ ] ) ;
134
131
return addresses . map ( ( address ) => {
135
- const isRegistered = isLastStakeKeyCertOfType (
132
+ const regCert = lastStakeKeyCertOfType (
136
133
transactions . map (
137
134
( {
138
135
tx : {
@@ -143,23 +140,31 @@ const getAccountsKeyStatus =
143
140
Cardano . StakeRegistrationCertificateTypes ,
144
141
address
145
142
) ;
146
- const isRegistering = isLastStakeKeyCertOfType (
143
+
144
+ let deposit : Cardano . Lovelace | undefined ;
145
+ if ( regCert && Cardano . isCertType ( regCert , Cardano . PostConwayStakeRegistrationCertificateTypes ) ) {
146
+ deposit = regCert . deposit ;
147
+ }
148
+
149
+ const isRegistering = ! ! lastStakeKeyCertOfType (
147
150
certificatesInFlight ,
148
151
Cardano . StakeRegistrationCertificateTypes ,
149
152
address
150
153
) ;
151
- const isUnregistering = isLastStakeKeyCertOfType (
154
+ const isUnregistering = ! ! lastStakeKeyCertOfType (
152
155
certificatesInFlight ,
153
156
[ Cardano . CertificateType . StakeDeregistration , Cardano . CertificateType . Unregistration ] ,
154
157
address
155
158
) ;
156
- return isRegistering
159
+ const keyStatus = isRegistering
157
160
? Cardano . StakeKeyStatus . Registering
158
161
: isUnregistering
159
162
? Cardano . StakeKeyStatus . Unregistering
160
- : isRegistered
163
+ : regCert
161
164
? Cardano . StakeKeyStatus . Registered
162
165
: Cardano . StakeKeyStatus . Unregistered ;
166
+
167
+ return { ...( keyStatus === Cardano . StakeKeyStatus . Registered && { deposit } ) , keyStatus } ;
163
168
} ) ;
164
169
} ;
165
170
@@ -173,11 +178,15 @@ const accountCertificateTransactions = (
173
178
transactions
174
179
. map ( ( { tx, epoch } ) => ( {
175
180
certificates : ( tx . body . certificates || [ ] )
176
- . filter ( ( cert ) : cert is Cardano . RegAndDeregCertificateUnion | Cardano . StakeDelegationCertificateUnion =>
177
- [ ...Cardano . RegAndDeregCertificateTypes , ...Cardano . StakeDelegationCertificateTypes ] . includes (
178
- cert . __typename as Cardano . RegAndDeregCertificateTypes | Cardano . StakeDelegationCertificateTypes
179
- )
181
+ . map ( ( cert ) =>
182
+ Cardano . isCertType ( cert , [
183
+ ...Cardano . RegAndDeregCertificateTypes ,
184
+ ...Cardano . StakeDelegationCertificateTypes
185
+ ] )
186
+ ? cert
187
+ : null
180
188
)
189
+ . filter ( isNotNil )
181
190
. filter ( ( cert ) => ( cert . stakeCredential . hash as unknown as Crypto . Ed25519KeyHashHex ) === stakeKeyHash ) ,
182
191
epoch
183
192
} ) )
@@ -204,15 +213,19 @@ export const getStakePoolIdAtEpoch = (transactions: TransactionsCertificates) =>
204
213
const certificatesUpToEpoch = transactions
205
214
. filter ( ( { epoch } ) => epoch < atEpoch - 2 )
206
215
. map ( ( { certificates } ) => certificates ) ;
207
- if ( ! isLastStakeKeyCertOfType ( certificatesUpToEpoch , Cardano . StakeRegistrationCertificateTypes ) ) {
216
+ if ( ! lastStakeKeyCertOfType ( certificatesUpToEpoch , Cardano . StakeRegistrationCertificateTypes ) ) {
208
217
return ;
209
218
}
210
219
211
220
const delegationTxCertificates = findLast ( certificatesUpToEpoch , ( certs ) =>
212
221
Cardano . includesAnyCertificate ( certs , Cardano . StakeDelegationCertificateTypes )
213
222
) ;
214
223
if ( ! delegationTxCertificates ) return ;
215
- return findLast ( delegationTxCertificates . filter ( isDelegationCertificate ) ) ?. poolId ;
224
+ return findLast (
225
+ delegationTxCertificates
226
+ . map ( ( cert ) => ( Cardano . isCertType ( cert , Cardano . StakeDelegationCertificateTypes ) ? cert : null ) )
227
+ . filter ( isNotNil )
228
+ ) ?. poolId ;
216
229
} ;
217
230
218
231
export const createDelegateeTracker = (
@@ -304,15 +317,16 @@ export const addressRewards = (
304
317
export const toRewardAccounts =
305
318
( addresses : Cardano . RewardAccount [ ] ) =>
306
319
( [ statuses , delegatees , rewards ] : [
307
- Cardano . StakeKeyStatus [ ] ,
320
+ { keyStatus : Cardano . StakeKeyStatus ; deposit ?: Cardano . Lovelace } [ ] ,
308
321
( Cardano . Delegatee | undefined ) [ ] ,
309
322
Cardano . Lovelace [ ]
310
323
] ) =>
311
324
addresses . map (
312
325
( address , i ) : Cardano . RewardAccountInfo => ( {
313
326
address,
314
327
delegatee : delegatees [ i ] ,
315
- keyStatus : statuses [ i ] ,
328
+ deposit : statuses [ i ] . deposit ,
329
+ keyStatus : statuses [ i ] . keyStatus ,
316
330
rewardBalance : rewards [ i ]
317
331
} )
318
332
) ;
0 commit comments