Getting Data
The SDK-Core of Superfluid allows querying data about user interactions with the Superfluid protocol. This guide details how to write subgraph queries and get account data, both directly and via the Framework.
Pre-Defined Subgraph Queries
Queries You Can Use via the SDK
Once the framework is initialized, you can run pre-defined queries like this:
const { Framework } = require("@superfluid-finance/sdk-core");
const { ethers } = require("ethers");
const provider = new ethers.providers.InfuraProvider(
"matic",
"<INFURA_API_KEY>"
);
const sf = await Framework.create({
networkName: "matic",
provider
});
type Paging = { take: number, skip?: number, lastId?: string };
const pageResult = await sf.query.
// The different queries can take different order by properties
// given the properties that exist on the entity itself.
listAllSuperTokens({ isListed?: boolean },
paging: Paging,
ordering: Ordering<Token_OrderBy>
);
listIndexes({ indexId?: string, publisher?: string, token?: string },
paging: Paging,
ordering: Ordering<Index_OrderBy>
);
listIndexSubscriptions({ subscriber?: string, approved?: boolean },
paging: Paging,
ordering: Ordering<IndexSubscription_OrderBy>
);
listStreams({ sender?: string, receiver?: string, token?: string },
paging: Paging,
ordering: Ordering<Stream_OrderBy>
);
listUserInteractedSuperTokens({ account?: string, token?: string },
paging: Paging,
ordering: Ordering<AccountTokenSnapshot_OrderBy>
);
listEvents({ account?: string, timestamp_gt?: number },
paging: Paging,
ordering: Ordering<Event_OrderBy>
);
// A subscription function which allows you to subscribe to events via polling.
on(
callback: (events: AllEvents[], unsubscribe: () => void) => void,
ms: number,
account?: string,
timeout?: number
)
Direct Initialization of Query Class
import { Query } from "@superfluid-finance/sdk-core";
const query = new Query({
customSubgraphQueriesEndpoint: "<A_CUSTOM_ENDPOINT>",
dataMode: "SUBGRAPH_ONLY" | "SUBGRAPH_WEB3" | "WEB3_ONLY"
});
Pagination and Ordering in Queries
All of the pre-defined query functions will accept pagination options: ({ skip: number, take: number }
), if you don't pass anything in, it will use a default of: { skip: 0, take: 100 }
. You can also paginate by lastId, this allows you to bypass the limitation of the max skip of 5000 entities.
// Example of Pagination and Ordering
const results = await sf.query.listAllSuperTokens(
{ isListed: true },
{ skip: 5, take: 150 },
{
orderBy: "createdAtBlockNumber",
orderDirection: "desc"
}
);
Getting Data from Agreements
Money Streaming Read Operations
// Read functions
await sf.cfaV1.getFlow({
superToken: string,
sender: string,
receiver: string,
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await sf.cfaV1.getAccountFlowInfo({
superToken: string,
account: string,
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await sf.cfaV1.getNetFlow({
superToken: string,
account: string,
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
Instant Distributions Read Operations
// Read functions
await sf.idaV1.getSubscription({
superToken: string,
publisher: string,
indexId: string,
subscriber: string,
providerOrSigner: string
});
await sf.idaV1.getIndex({
superToken: string,
publisher: string,
indexId: string,
providerOrSigner: string
});
Super Token Read Operations
// Read functions
await usdcx.balanceOf({
account: string,
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await usdcx.allowance({
owner: string,
spender: string,
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await usdcx.name({
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await usdcx.symbol({
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
await usdcx.totalSupply({
providerOrSigner: ethers.providers.Provider | ethers.Signer
});
This guide covers how to utilize the SDK Core to query data about accounts and their interactions with the Superfluid protocol. It includes details on running pre-defined subgraph queries, direct initialization of the Query class, and obtaining data from various agreements like CFAV1 and IDAV1.