Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/huma-sdk/src/services/ReceivableService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Pagination, SubgraphService } from './SubgraphService'
async function getTokenIdByURI(
signer: ethers.Signer,
uri: string | null,
apiKey?: string,
): Promise<string | null | undefined> {
if (uri === null) {
return null
Expand All @@ -57,7 +58,10 @@ async function getTokenIdByURI(
}
`

const receivableSubgraph = SubgraphService.getSubgraphUrlForChainId(chainId)
const receivableSubgraph = SubgraphService.getSubgraphUrlForChainId(
chainId,
apiKey,
)
if (!receivableSubgraph) {
throw new Error('No receivable subgraph exists for this chain')
}
Expand Down
24 changes: 17 additions & 7 deletions packages/huma-sdk/src/services/SubgraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ function getCreditEventsForUser(
poolName: POOL_NAME,
poolType: POOL_TYPE,
event: number[],
apiKey?: string,
): Promise<CreditEventPayload[]> {
const url = getSubgraphUrlForChainId(chainId)
const url = getSubgraphUrlForChainId(chainId, apiKey)
if (!url) {
return Promise.resolve([])
}
Expand Down Expand Up @@ -133,10 +134,16 @@ function getLastFactorizedAmountFromPool(
chainId: number,
poolName: POOL_NAME,
poolType: POOL_TYPE,
apiKey?: string,
): Promise<number> {
return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
CreditEvent.DrawdownMadeWithReceivable,
]).then((events) => Number(events[0].amount))
return getCreditEventsForUser(
userAddress,
chainId,
poolName,
poolType,
[CreditEvent.DrawdownMadeWithReceivable],
apiKey,
).then((events) => Number(events[0].amount))
}

/**
Expand All @@ -161,8 +168,9 @@ function getRWReceivableInfo(
orderBy: 'tokenId',
orderDirection: 'desc',
},
apiKey?: string,
): Promise<RealWorldReceivableInfoBase[]> {
const url = getSubgraphUrlForChainId(chainId)
const url = getSubgraphUrlForChainId(chainId, apiKey)
if (!url) {
return Promise.resolve([])
}
Expand Down Expand Up @@ -334,8 +342,9 @@ function checkBorrowAndLendHistory(
chainId: number,
pool: string,
userAddress: string,
apiKey?: string,
): Promise<{ hasBorrowHistory: boolean; hasLendHistory: boolean } | undefined> {
const url = getSubgraphUrlForChainId(chainId)
const url = getSubgraphUrlForChainId(chainId, apiKey)
if (!url || !userAddress || !pool) {
return Promise.resolve(undefined)
}
Expand Down Expand Up @@ -579,8 +588,9 @@ export type AccountData = {
function fetchAllAccountData(
chainId: number,
account: string,
apiKey?: string,
): Promise<AccountData | undefined> {
const url = PoolSubgraphMap[chainId]?.subgraph
const url = getSubgraphUrlForChainId(chainId, apiKey)
if (!url) {
return Promise.resolve(undefined)
}
Expand Down
Loading