@@ -9,9 +9,11 @@ import { TTokenSelected, tTokensSelectors } from '../../../database/selectors';
99import {
1010 fetchPoolList ,
1111 fetchPoolReserves ,
12+ fetchUserReserves ,
1213 selectPoolById ,
1314} from '../../../libs/loaders/money-market' ;
1415import { paginationResponse , paginationSchema } from '../../../libs/pagination' ;
16+ import { transformUserReservesData } from '../../../libs/utils/user-reserves' ;
1517
1618interface ReserveDataHumanized {
1719 originalId : number ;
@@ -262,4 +264,88 @@ export default async function (fastify: FastifyInstance) {
262264 // };
263265 } ,
264266 ) ;
267+
268+ fastify . withTypeProvider < ZodTypeProvider > ( ) . get (
269+ '/money-market/:pool/user/:address/lendings' ,
270+ {
271+ schema : {
272+ querystring : paginationSchema ,
273+ params : z . object ( {
274+ pool : z . string ( ) ,
275+ address : z . string ( ) ,
276+ } ) ,
277+ } ,
278+ config : {
279+ cache : true ,
280+ } ,
281+ } ,
282+ async (
283+ req : FastifyRequest < { Params : { pool : string ; address : string } } > ,
284+ reply ,
285+ ) => {
286+ const pools = await fetchPoolList ( req . chain . chainId ) ;
287+ const pool = selectPoolById ( req . params . pool , pools ) ;
288+
289+ if ( ! pool ) return reply . notFound ( 'Pool not found' ) ;
290+
291+ const userReservesRaw = await fetchUserReserves (
292+ req . chain . chainId ,
293+ pool ,
294+ req . params . address ,
295+ ) ;
296+
297+ const activePositions = userReservesRaw . filter (
298+ ( r ) => r . scaledATokenBalance > 0n ,
299+ ) ;
300+
301+ return transformUserReservesData ( {
302+ chainId : req . chain . chainId ,
303+ userAddress : req . params . address ,
304+ pool,
305+ reserves : activePositions ,
306+ } ) ;
307+ } ,
308+ ) ;
309+
310+ fastify . withTypeProvider < ZodTypeProvider > ( ) . get (
311+ '/money-market/:pool/user/:address/borrowings' ,
312+ {
313+ schema : {
314+ querystring : paginationSchema ,
315+ params : z . object ( {
316+ pool : z . string ( ) ,
317+ address : z . string ( ) ,
318+ } ) ,
319+ } ,
320+ config : {
321+ cache : true ,
322+ } ,
323+ } ,
324+ async (
325+ req : FastifyRequest < { Params : { pool : string ; address : string } } > ,
326+ reply ,
327+ ) => {
328+ const pools = await fetchPoolList ( req . chain . chainId ) ;
329+ const pool = selectPoolById ( req . params . pool , pools ) ;
330+
331+ if ( ! pool ) return reply . notFound ( 'Pool not found' ) ;
332+
333+ const userReservesRaw = await fetchUserReserves (
334+ req . chain . chainId ,
335+ pool ,
336+ req . params . address ,
337+ ) ;
338+
339+ const activeBorrows = userReservesRaw . filter (
340+ ( r ) => r . scaledVariableDebt > 0n || r . principalStableDebt > 0n ,
341+ ) ;
342+
343+ return transformUserReservesData ( {
344+ chainId : req . chain . chainId ,
345+ userAddress : req . params . address ,
346+ pool,
347+ reserves : activeBorrows ,
348+ } ) ;
349+ } ,
350+ ) ;
265351}
0 commit comments