@hashgraphonline/standards-sdk
Version:
The Hashgraph Online Standards SDK provides a complete implementation of the Hashgraph Consensus Standards (HCS), giving developers all the tools needed to build applications on Hedera.
115 lines (113 loc) • 5.71 kB
TypeScript
import { FeeConfigBuilderInterface, TopicFeeConfig } from './types';
import { Logger } from '../utils/logger';
import { NetworkType } from '../utils/types';
/**
* FeeConfigBuilder provides a fluent interface for creating fee configurations
* for HCS-10 topics. This makes it easy to configure fees without dealing with
* the complexity of the underlying fee structure.
*
* Example usage:
*
* // Super simple one-liner with the factory method
* const simpleFeeConfig = FeeConfigBuilder.forHbar(5, '0.0.12345', NetworkType.TESTNET, new Logger(), ['0.0.67890']);
*
* // With multiple fees:
* const multipleFeeConfig = new FeeConfigBuilder({
* network: NetworkType.TESTNET,
* logger: new Logger(),
* defaultCollectorAccountId: '0.0.12345',
* defaultExemptAccountIds: ['0.0.67890']
* })
* .withHbarFee(1) // 1 HBAR fee
* .withTokenFee(10, '0.0.54321') // 10 units of token 0.0.54321
* .build();
*
* With Agent Builder
* const agent = new AgentBuilder()
* .setName('Fee Collector Agent')
* .setDescription('An agent that collects fees')
* .setInboundTopicType(InboundTopicType.FEE_BASED)
* .setFeeConfig(FeeConfigBuilder.forHbar(1, '0.0.12345', NetworkType.TESTNET, new Logger(), ['0.0.67890']))
* .setNetwork('testnet')
.build();
* Directly with client
* const client = new HCS10Client(config);
* const connectionFeeConfig = new FeeConfigBuilder({
* network: NetworkType.TESTNET,
* logger: new Logger(),
* defaultCollectorAccountId: client.getAccountAndSigner().accountId,
* defaultExemptAccountIds: ['0.0.67890']
* })
* .withHbarFee(0.5) // 0.5 HBAR (simple!)
* .build();
* const result = await client.handleConnectionRequest(
* inboundTopicId,
* requestingAccountId,
* connectionRequestId,
* connectionFeeConfig
* );
*/
export interface FeeConfigBuilderOptions {
network: NetworkType;
logger: Logger;
defaultCollectorAccountId?: string;
}
export declare class FeeConfigBuilder implements FeeConfigBuilderInterface {
private customFees;
private mirrorNode;
private logger;
private defaultCollectorAccountId;
constructor(options: FeeConfigBuilderOptions);
/**
* Static factory method to create a FeeConfigBuilder with a single HBAR fee.
* @param hbarAmount Amount in HBAR.
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
* @param network Network type ('mainnet' or 'testnet').
* @param logger Logger instance.
* @param exemptAccounts Optional array of account IDs exempt from this fee.
* @returns A configured FeeConfigBuilder instance.
*/
static forHbar(hbarAmount: number, collectorAccountId: string | undefined, network: NetworkType, logger: Logger, exemptAccounts?: string[]): FeeConfigBuilder;
/**
* Static factory method to create a FeeConfigBuilder with a single token fee.
* Automatically fetches token decimals if not provided.
* @param tokenAmount Amount of tokens.
* @param feeTokenId Token ID for the fee.
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
* @param network Network type ('mainnet' or 'testnet').
* @param logger Logger instance.
* @param exemptAccounts Optional array of account IDs exempt from this fee.
* @param decimals Optional decimals for the token (fetched if omitted).
* @returns A Promise resolving to a configured FeeConfigBuilder instance.
*/
static forToken(tokenAmount: number, feeTokenId: string, collectorAccountId: string | undefined, network: NetworkType, logger: Logger, exemptAccounts?: string[], decimals?: number): Promise<FeeConfigBuilder>;
/**
* Adds an HBAR fee configuration to the builder.
* Allows chaining multiple fee additions.
* @param hbarAmount The amount in HBAR (e.g., 0.5).
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.
* @returns This FeeConfigBuilder instance for chaining.
*/
addHbarFee(hbarAmount: number, collectorAccountId?: string, exemptAccountIds?: string[]): FeeConfigBuilder;
/**
* Adds a token fee configuration to the builder.
* Allows chaining multiple fee additions.
* Fetches token decimals automatically if not provided.
* @param tokenAmount The amount of the specified token.
* @param feeTokenId The ID of the token to charge the fee in.
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
* @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.
* @returns A Promise resolving to this FeeConfigBuilder instance for chaining.
*/
addTokenFee(tokenAmount: number, feeTokenId: string, collectorAccountId?: string, decimals?: number, exemptAccountIds?: string[]): Promise<FeeConfigBuilder>;
/**
* Builds the final TopicFeeConfig object.
* @returns The TopicFeeConfig containing all added custom fees and a consolidated list of unique exempt accounts.
* @throws Error if no fees have been added.
* @throws Error if more than 10 fees have been added.
*/
build(): TopicFeeConfig;
}
//# sourceMappingURL=fee-config-builder.d.ts.map