Skip to content

Commit 5e1a665

Browse files
committed
fix(cardano-serices): add (partial) stake pool parameters to stake pool registration certificates
1 parent 50cdd54 commit 5e1a665

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BlockOutputModel,
66
CertificateModel,
77
MultiAssetModel,
8+
PoolRegisterCertModel,
89
ProtocolParametersUpdateModel,
910
RedeemerModel,
1011
ScriptModel,
@@ -191,6 +192,17 @@ const mapDrepDelegation = ({
191192
__typename: 'AlwaysAbstain'
192193
};
193194

195+
const mapPoolParameters = (certModel: WithCertType<PoolRegisterCertModel>): Cardano.PoolParameters => ({
196+
cost: BigInt(certModel.fixed_cost),
197+
id: certModel.pool_id as unknown as Cardano.PoolId,
198+
margin: Cardano.FractionUtils.toFraction(certModel.margin),
199+
owners: [],
200+
pledge: BigInt(certModel.pledge),
201+
relays: [],
202+
rewardAccount: certModel.reward_account as Cardano.RewardAccount,
203+
vrf: certModel.vrf_key_hash.toString('hex') as Cardano.VrfVkHex
204+
});
205+
194206
// eslint-disable-next-line complexity
195207
export const mapCertificate = (
196208
certModel: WithCertType<CertificateModel>
@@ -209,7 +221,7 @@ export const mapCertificate = (
209221
__typename: Cardano.CertificateType.PoolRegistration,
210222
cert_index: certModel.cert_index,
211223
deposit: BigInt(certModel.deposit),
212-
poolParameters: null as unknown as Cardano.PoolParameters
224+
poolParameters: mapPoolParameters(certModel)
213225
} as WithCertIndex<Cardano.HydratedPoolRegistrationCertificate>;
214226

215227
if (isMirCertModel(certModel)) {

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/queries.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,21 @@ export const findPoolRetireCertsTxIds = `
250250
export const findPoolRegisterCertsByTxIds = `
251251
SELECT
252252
cert.cert_index AS cert_index,
253-
pool."view" AS pool_id,
253+
pool.view AS pool_id,
254254
tx.hash AS tx_id,
255255
CASE
256256
WHEN cert.deposit IS NULL THEN '0'
257257
ELSE cert.deposit
258-
END AS deposit
258+
END AS deposit,
259+
stake_address.view AS reward_account,
260+
pledge,
261+
fixed_cost,
262+
margin,
263+
vrf_key_hash
259264
FROM tx
260265
JOIN pool_update AS cert ON cert.registered_tx_id = tx.id
261266
JOIN pool_hash AS pool ON pool.id = cert.hash_id
267+
JOIN stake_address ON stake_address.id = reward_addr_id
262268
WHERE tx.id = ANY($1)
263269
ORDER BY tx.id ASC`;
264270

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ export interface PoolRetireCertModel extends CertificateModel {
178178
export interface PoolRegisterCertModel extends CertificateModel {
179179
pool_id: string;
180180
deposit: string;
181+
reward_account: string;
182+
pledge: string;
183+
fixed_cost: string;
184+
margin: number;
185+
vrf_key_hash: Buffer;
181186
}
182187

183188
export interface MirCertModel extends CertificateModel {

packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const blockHash = '7a48b034645f51743550bbaf81f8a14771e58856e031eb63844738ca8ad72
3434
const poolId = 'pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh';
3535
const datetime = '2022-05-10T19:22:43.620Z';
3636
const vrfKey = 'vrf_vk19j362pkr4t9y0m3qxgmrv0365vd7c4ze03ny4jh84q8agjy4ep4s99zvg8';
37+
const vrfKeyHash = '220ba9398e3e5fae23a83d0d5927649d577a5f69d6ef1d5253c259d9393ba294';
3738
const genesisLeaderHash = 'eff1b5b26e65b791d6f236c7c0264012bd1696759d22bdb4dd0f6f56';
3839
const transactionHash = 'cefd2fcf657e5e5d6c35975f4e052f427819391b153ebb16ad8aa107ba5a3819';
3940
const sourceTransactionHash = 'cefd2fcf657e5e5d6c35975f4e052f427819391b153ebb16ad8aa107ba5a3812';
@@ -292,14 +293,28 @@ describe('chain history mappers', () => {
292293
const result = mappers.mapCertificate({
293294
...baseCertModel,
294295
deposit: '500000000',
296+
fixed_cost: '390000000',
297+
margin: 0.15,
298+
pledge: '420000000',
295299
pool_id: poolId,
296-
type: 'register'
300+
reward_account: stakeAddress,
301+
type: 'register',
302+
vrf_key_hash: Buffer.from(vrfKeyHash, 'hex')
297303
} as WithCertType<PoolRegisterCertModel>);
298304
expect(result).toEqual<WithCertIndex<Cardano.HydratedPoolRegistrationCertificate>>({
299305
__typename: Cardano.CertificateType.PoolRegistration,
300306
cert_index: 0,
301307
deposit: 500_000_000n,
302-
poolParameters: null as unknown as Cardano.PoolParameters
308+
poolParameters: {
309+
cost: 390_000_000n,
310+
id: poolId as Cardano.PoolId,
311+
margin: { denominator: 20, numerator: 3 },
312+
owners: [],
313+
pledge: 420_000_000n,
314+
relays: [],
315+
rewardAccount: stakeAddress as Cardano.RewardAccount,
316+
vrf: vrfKeyHash as Cardano.VrfVkHex
317+
}
303318
});
304319
});
305320
test('map MirCertModel to Cardano.MirCertificate', () => {

0 commit comments

Comments
 (0)