Skip to content

Commit b39cf0e

Browse files
Alex Steleaclaude
andauthored
Fix Surge margin pool error handling to return zero positions instead of failing (#204)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 77e0a6c commit b39cf0e

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

packages/api/src/common/dapps/surge/getSurgeLiquidityPositions.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const GetFungibleBalanceLive = GetFungibleBalanceService.Default;
1414
const GetComponentStateLive = GetComponentStateService.Default;
1515
const GetEntityDetailsServiceLive = GetEntityDetailsService.Default;
1616
const EntityFungiblesPageLive = EntityFungiblesPageService.Default;
17-
const GetLedgerStateLive = GetLedgerStateService.Default;
17+
const GetLedgerStateLive = GetLedgerStateService.Default.pipe(
18+
Layer.provide(GatewayApiClientLive),
19+
);
1820

1921
const getSurgeLiquidityPositionsLive = GetSurgeLiquidityPositionsLive.pipe(
2022
Layer.provide(GetFungibleBalanceLive),
@@ -29,14 +31,26 @@ describe('GetSurgeLiquidityPositionsService', () => {
2931
it('should get surge liquidity positions', async () => {
3032
const result = await Effect.runPromiseExit(
3133
Effect.gen(function* () {
32-
const service = yield* GetSurgeLiquidityPositionsService;
34+
const service = yield* Effect.provide(
35+
GetSurgeLiquidityPositionsService,
36+
getSurgeLiquidityPositionsLive,
37+
);
38+
const getLedgerState = yield* Effect.provide(
39+
GetLedgerStateService,
40+
GetLedgerStateLive,
41+
);
42+
43+
const state = yield* getLedgerState({
44+
at_ledger_state: { timestamp: new Date('2024-09-01T00:00:00Z') },
45+
});
46+
3347
return yield* service.getSurgeLiquidityPositions({
3448
accountAddresses: [
3549
'account_rdx12x7dulvhrvz2ney3992n5y4y590cqj58ge5y2xesjlkzgrydg8xdd7',
3650
],
37-
at_ledger_state: { state_version: 325927555 },
51+
at_ledger_state: { state_version: state.state_version },
3852
});
39-
}).pipe(Effect.provide(getSurgeLiquidityPositionsLive)),
53+
}),
4054
);
4155

4256
Exit.match(result, {

packages/api/src/common/dapps/surge/getSurgeLiquidityPositions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ export class GetSurgeLiquidityPositionsService extends Effect.Service<GetSurgeLi
6262
});
6363

6464
if (!marginPoolComponentState) {
65-
return yield* Effect.fail(
66-
new SlpNotFoundError(
67-
'Margin pool component not found at state version',
68-
),
69-
);
65+
// If margin pool component state is not found, return 0 liquidity position for all accounts
66+
return input.accountAddresses.map((address) => ({
67+
address,
68+
liquidityPosition: {
69+
resourceAddress: Assets.Fungible.xUSDC,
70+
amount: new BigNumber(0),
71+
},
72+
}));
7073
}
7174

7275
// Get SLP total supply and sUSD balance of margin pool

0 commit comments

Comments
 (0)