Skip to content

Commit aff4f1c

Browse files
authored
refactor: correctly fetch vester state (#390)
1 parent e22d605 commit aff4f1c

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

packages/api/src/incentives/season-reward/incentives-vester/incentivesVester.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export class IncentivesVesterStateService extends Effect.Service<IncentivesVeste
426426
message: 'Incentives vester not found',
427427
}),
428428
),
429-
(result) => result.state,
429+
(result) => result.state.state[0],
430430
),
431431
),
432432
);

packages/api/src/incentives/season-reward/incentives-vester/schemas.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import s from 'sbor-ez-mode';
22
// Generated TypeScript schema for Scrypto SBOR types of package address: package_rdx1phe8ngw6fjahenrg9l5z548ve7u7z60a0pq98vkh6p2wf253xd6uh0
33

4-
export const Type4 = s.struct({
4+
export const UninitializedVestingConfig = s.struct({
55
vest_duration_seconds: s.number(),
66
pre_claim_duration_seconds: s.number(),
77
initial_vested_fraction: s.decimal(),
88
});
99

10+
export const InitializedVestingConfig = s.struct({
11+
vest_start: s.instant(),
12+
vest_end: s.instant(),
13+
initial_vested_fraction: s.decimal(),
14+
});
15+
1016
export const VestingConfiguration = s.enum([
11-
{ variant: 'Uninitialized', schema: Type4 },
12-
{ variant: 'Initialized', schema: Type4 },
17+
{ variant: 'Uninitialized', schema: UninitializedVestingConfig },
18+
{ variant: 'Initialized', schema: InitializedVestingConfig },
1319
]);
1420

1521
export const ResolvedVestingState = s.struct({

packages/api/src/incentives/season-reward/incentives-vester/seasonVester.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { DbService } from '../../db/dbClient';
88
import type { AccountWithLabel } from './seasonVester';
99
import { SeasonVesterService } from './seasonVester';
1010

11-
const STATE_VERSION = 430517688;
11+
const STATE_VERSION = 442444027;
1212
const COMPONENT_ADDRESS =
13-
'component_rdx1cqvk5tjxc2atwzj3vd88pfjpxav2dsam5y0qzydtsntrq9ajhh5a5j';
13+
'component_rdx1cpsdx6z53k5a3r5748pf2w0l5gyay8jxzlmgzpkd38pdpse6l8thge';
1414
const ACCOUNT_WITH_7_LP_TOKENS =
15-
'account_rdx12xl2meqtelz47mwp3nzd72jkwyallg5yxr9hkc75ac4qztsxulfpew';
15+
'account_rdx16y4gqnchvxeszcpswg2zldgsle6uqvnl0znerne70tw9535njhkgzk';
1616
const ACCOUNT_WITH_2_LP_TOKENS =
17-
'account_rdx129zryfdcuyvwl00rxkscec24re8wts0526fqqfphuv37n9z0cyd307';
17+
'account_rdx129ky0qmad6p7k0x5ck94dsyxgz4fjsg8w6cxx5dekz6yvg2mmcwgsx';
1818
const SEASON_ID = '036031e3-8bfb-4d2f-b653-f05c76f07704';
1919

2020
const TestLayer = SeasonVesterService.Default.pipe(
@@ -59,14 +59,14 @@ layer(TestLayer)('SeasonVesterService', (it) => {
5959

6060
expect(result).toBeDefined();
6161
expect(result.poolUnitResourceAddress).toBe(
62-
'resource_rdx1th428swhg2e46v23pkk46j89q40gyjzlkxt6f9sc9msu6tz9uklfqr',
62+
'resource_rdx1t5q63xdyuhdy32y8xp8hg48psyym9k7dhvya2lzvk4d555uk0krkq5',
6363
);
6464
expect(result.poolAddress).toBe(
65-
'pool_rdx1cjs3zwnwyj0ekrak5xhq9ewf938s58a0v0u93qpajhwlc7c9vcxyks',
65+
'pool_rdx1c33act32ruq0ynar35kgsn7ksug63apekwywapmj8s2rz4zpew0vdu',
6666
);
67-
expect(result.currentValuePerUnit).toBe('0.20019495180111618406');
68-
expect(result.maturityValuePerUnit).toBe('1.05560142046302400866');
69-
expect(result.vestEndTimestamp).toBe('2026-12-23T13:11:56.000Z');
67+
expect(result.currentValuePerUnit).toBe('0');
68+
expect(result.maturityValuePerUnit).toBe('1');
69+
expect(result.vestEndTimestamp).toBe('2027-01-22T10:07:38.000Z');
7070
}).pipe(Effect.provide(DbService.Default)),
7171
);
7272

packages/api/src/incentives/season-reward/incentives-vester/seasonVester.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ export class SeasonVesterService extends Effect.Service<SeasonVesterService>()(
9292

9393
const poolAddress = PoolAddress(vesterState.pool);
9494

95-
// Handle Option type for vest_end
95+
// Get vest_end from vesting configuration if initialized
9696
const vestEndTimestamp =
97-
vesterState.vest_end.variant === 'Some'
98-
? vesterState.vest_end.value
97+
vesterState.vesting_configuration.variant === 'Initialized'
98+
? vesterState.vesting_configuration.value.vest_end
9999
: null;
100100

101101
// Get pool unit info (LP token address and current value)

0 commit comments

Comments
 (0)