From 9caece0411997d09f55744cd3caf9c01d5e02e33 Mon Sep 17 00:00:00 2001 From: 0xPeluche <0xpeluche@proton.me> Date: Thu, 29 Feb 2024 14:12:57 +0100 Subject: [PATCH] fix_reflexer, handler if fetch is nullish --- src/adapters/reflexer/ethereum/farm.ts | 58 +++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/adapters/reflexer/ethereum/farm.ts b/src/adapters/reflexer/ethereum/farm.ts index a7b67589a..379ffff28 100644 --- a/src/adapters/reflexer/ethereum/farm.ts +++ b/src/adapters/reflexer/ethereum/farm.ts @@ -1,5 +1,6 @@ import type { Balance, BalancesContext, BorrowBalance, LendBalance } from '@lib/adapter' import type { Token } from '@lib/token' +import { isNotNullish } from '@lib/type' import request, { gql } from 'graphql-request' const WETH: Token = { @@ -28,7 +29,7 @@ interface ReflexerBorrowBalancesParams extends BorrowBalance { const url = 'https://api.thegraph.com/subgraphs/name/reflexer-labs/rai-mainnet' -export async function getReflexerFarmBalancesWithProxies(ctx: BalancesContext): Promise { +export async function getReflexerFarmBalancesWithProxies(ctx: BalancesContext): Promise { const query = gql` query proxies { user(id: "${ctx.address}") { @@ -46,35 +47,34 @@ export async function getReflexerFarmBalancesWithProxies(ctx: BalancesContext): } ` - const res: any = await request(url, query) + const { user }: any = await request(url, query) + if (isNotNullish(user)) { + return user.safes.flatMap((safe: any) => { + const { safeHandler, safeId, collateral, debt } = safe - const balances: Balance[] = res.user.safes.flatMap((safe: any) => { - const { safeHandler, safeId, collateral, debt } = safe - - const lend: ReflexerLendBalancesParams = { - chain: 'ethereum', - address: WETH.address, - proxy: res.user.proxies[0].id, - safe: { safeHandler, safeId }, - amount: BigInt(Math.round(collateral * Math.pow(10, WETH.decimals))), - underlyings: undefined, - rewards: undefined, - category: 'lend', - } - - const borrow: ReflexerBorrowBalancesParams = { - chain: 'ethereum', - address: RAI.address, - proxy: res.user.proxies[0].id, - safe: { safeHandler, safeId }, - amount: BigInt(Math.round(debt * Math.pow(10, RAI.decimals))), - underlyings: undefined, - rewards: undefined, - category: 'borrow', - } + const lend: ReflexerLendBalancesParams = { + chain: 'ethereum', + address: WETH.address, + proxy: user.proxies[0].id, + safe: { safeHandler, safeId }, + amount: BigInt(Math.round(collateral * Math.pow(10, WETH.decimals))), + underlyings: undefined, + rewards: undefined, + category: 'lend', + } - return [lend, borrow] - }) + const borrow: ReflexerBorrowBalancesParams = { + chain: 'ethereum', + address: RAI.address, + proxy: user.proxies[0].id, + safe: { safeHandler, safeId }, + amount: BigInt(Math.round(debt * Math.pow(10, RAI.decimals))), + underlyings: undefined, + rewards: undefined, + category: 'borrow', + } - return balances + return [lend, borrow] + }) + } }