Instant Distributions (SDK)
The InstantDistributionAgreementV1 (IDA) helper class in the Superfluid SDK Core facilitates one-to-many transactions. This guide demonstrates how to access and use this class via the Framework class or as a standalone class.
Using the Framework Class
Initializing and Using IDA via Framework
import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";
const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider: /* Replace with your provider */
});
// Access the idaV1 object via the Framework class
const flowInfo = await sf.idaV1.getSubscription(...); // Replace '...' with actual parameters
Direct Initialization
Initializing IDA Directly
import { InstantDistributionAgreementV1 } from "@superfluid-finance/sdk-core";
const config = {
hostAddress: "0x3E14dC1b13c488a8d5D310918780c983bD5982E7",
cfaV1Address: "0x6EeE6060f715257b970700bc2656De21dEdF074C",
idaV1Address: "0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1"
};
// Load a super token
const daix = await sf.loadSuperToken("DAIx");
const idaV1 = new InstantDistributionAgreementV1({ options: config });
IDAV1 Functions
Read and Write Operations with IDA
const daix = await sf.loadSuperToken("DAIx");
// Read functions
await daix.getSubscription({
publisher: "0x...", // Replace with publisher's address
indexId: "1", // Replace with index ID
subscriber: "0x...", // Replace with subscriber's address
providerOrSigner: provider // Replace with provider or signer
});
await daix.getIndex({
publisher: "0x...", // Replace with publisher's address
indexId: "1", // Replace with index ID
providerOrSigner: provider // Replace with provider or signer
});
// Write operations
daix.createIndex({
indexId: "0", // Replace with index ID
userData: "0x..." // Replace with user data
});
// Other write operations similar to the above example
Example Usage
Reading and Writing with IDA
import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";
const provider = new ethers.providers.InfuraProvider("matic", "<INFURA_API_KEY>");
const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider
});
const daix = await sf.loadSuperToken("DAIx");
// Read example
const subscription = await daix.getSubscription({
publisher: "0x...", // Replace with publisher's address
indexId: "1", // Replace with index ID
subscriber: "0x...", // Replace with subscriber's address
providerOrSigner: provider
});
console.log(subscription);
// Write operation example
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
const createIndexOperation = daix.createIndex({ indexId: "0", userData: "0x" });
const txnResponse = await createIndexOperation.exec(signer);
const txnReceipt = await txnResponse.wait();
This guide covers the initialization and usage of the InstantDistributionAgreementV1 class in the Superfluid SDK Core. It includes both framework-based and direct initialization methods, along with examples of read and write operations.