@openzeppelin/ui-builder-adapter-stellar
Version:
Stellar Adapter for UI Builder
181 lines (171 loc) • 8.11 kB
text/typescript
import React from 'react';
import { WalletConnectionStatus, ContractAdapter, StellarNetworkConfig, UiKitConfiguration, FormFieldType, ContractSchema, FieldType, FunctionParameter, ExecutionConfig, TxStatus, TransactionStatusUpdate, ContractFunction, Connector, ExecutionMethodDetail, AvailableUiKit, NativeConfigLoader, EcosystemWalletComponents, EcosystemReactUiProviderProps, EcosystemSpecificReactHooks, RelayerDetails, RelayerDetailsRich, UserRpcProviderConfig, AdapterConfig } from '@openzeppelin/ui-builder-types';
/**
* Stellar-specific wallet connection status extending the base interface.
* Includes Stellar-specific fields like walletId.
* Note that stellar wallets don't work with multiple addresses, only a single active address.
*/
interface StellarWalletConnectionStatus extends WalletConnectionStatus {
/** Stellar-specific wallet identifier (e.g., 'freighter', 'albedo') */
walletId?: string;
}
/**
* Stellar-specific adapter implementation using explicit method delegation.
*
* NOTE: Contains placeholder implementations for most functionalities.
*/
declare class StellarAdapter implements ContractAdapter {
readonly networkConfig: StellarNetworkConfig;
readonly initialAppServiceKitName: UiKitConfiguration['kitName'];
constructor(networkConfig: StellarNetworkConfig);
/**
* NOTE about artifact inputs (single input with auto-detection):
*
* The Builder renders the contract definition step using whatever fields the
* adapter returns here. EVM uses one optional ABI field; Midnight provides
* multiple fields. Stellar should use a single input approach with automatic
* content detection when we add manual-spec support:
*
* - Keep `contractAddress` (required)
* - Add optional `contractDefinition` (type: `code-editor`, language: `json`)
* with file upload support for both JSON and Wasm binary content
*
* When this field is added:
* - Extend `validateAndConvertStellarArtifacts(...)` to accept
* `{ contractAddress, contractDefinition? }`
* - In the loader, branch: if `contractDefinition` provided, auto-detect
* content type (JSON vs Wasm using magic bytes `\0asm`):
* - For JSON: Parse and validate as Soroban spec, use `transformStellarSpecToSchema`
* - For Wasm: Extract embedded spec from binary, parse locally (no RPC)
* - Set `source: 'manual'` with `contractDefinitionOriginal` to the raw
* user-provided content. This ensures auto-save captures and restores the
* manual contract definition exactly like the EVM/Midnight flows.
* - Provide clear UI hints about supported formats (JSON spec or Wasm binary).
*/
getContractDefinitionInputs(): FormFieldType[];
/**
* @inheritdoc
*/
loadContract(source: string | Record<string, unknown>): Promise<ContractSchema>;
/**
* @inheritdoc
*/
loadContractWithMetadata(source: string | Record<string, unknown>): Promise<{
schema: ContractSchema;
source: 'fetched' | 'manual';
contractDefinitionOriginal?: string;
metadata?: {
fetchedFrom?: string;
contractName?: string;
fetchTimestamp?: Date;
definitionHash?: string;
};
}>;
getWritableFunctions(contractSchema: ContractSchema): ContractSchema['functions'];
mapParameterTypeToFieldType(parameterType: string): FieldType;
getCompatibleFieldTypes(parameterType: string): FieldType[];
generateDefaultField<T extends FieldType = FieldType>(parameter: FunctionParameter, contractSchema?: ContractSchema): FormFieldType<T>;
formatTransactionData(contractSchema: ContractSchema, functionId: string, submittedInputs: Record<string, unknown>, fields: FormFieldType[]): unknown;
signAndBroadcast(transactionData: unknown, executionConfig: ExecutionConfig, onStatusChange: (status: TxStatus, details: TransactionStatusUpdate) => void, runtimeApiKey?: string): Promise<{
txHash: string;
}>;
isViewFunction(functionDetails: ContractFunction): boolean;
queryViewFunction(contractAddress: string, functionId: string, params?: unknown[], contractSchema?: ContractSchema): Promise<unknown>;
formatFunctionResult(decodedValue: unknown, functionDetails: ContractFunction): string;
supportsWalletConnection(): boolean;
getAvailableConnectors(): Promise<Connector[]>;
connectWallet(connectorId: string): Promise<{
connected: boolean;
address?: string;
error?: string;
}>;
disconnectWallet(): Promise<{
disconnected: boolean;
error?: string;
}>;
getWalletConnectionStatus(): StellarWalletConnectionStatus;
/**
* @inheritdoc
*/
onWalletConnectionChange(callback: (currentStatus: WalletConnectionStatus, previousStatus: WalletConnectionStatus) => void): () => void;
getSupportedExecutionMethods(): Promise<ExecutionMethodDetail[]>;
validateExecutionConfig(config: ExecutionConfig): Promise<true | string>;
getExplorerUrl(address: string): string | null;
getExplorerTxUrl?(txHash: string): string | null;
isValidAddress(address: string, addressType?: string): boolean;
getAvailableUiKits(): Promise<AvailableUiKit[]>;
/**
* @inheritdoc
*/
configureUiKit(programmaticOverrides?: Partial<UiKitConfiguration>, options?: {
loadUiKitNativeConfig?: NativeConfigLoader;
}): Promise<void>;
/**
* @inheritdoc
*/
getExportableWalletConfigFiles(uiKitConfig?: UiKitConfiguration): Promise<Record<string, string>>;
/**
* @inheritdoc
*/
getEcosystemWalletComponents(): EcosystemWalletComponents | undefined;
/**
* @inheritdoc
*/
getEcosystemReactUiContextProvider(): React.ComponentType<EcosystemReactUiProviderProps> | undefined;
/**
* @inheritdoc
*/
getEcosystemReactHooks(): EcosystemSpecificReactHooks | undefined;
getRelayers(serviceUrl: string, accessToken: string): Promise<RelayerDetails[]>;
getRelayer(serviceUrl: string, accessToken: string, relayerId: string): Promise<RelayerDetailsRich>;
/**
* Returns a React component for configuring Stellar-specific relayer transaction options.
* @returns The Stellar relayer options component
*/
getRelayerOptionsComponent(): React.ComponentType<{
options: Record<string, unknown>;
onChange: (options: Record<string, unknown>) => void;
}> | undefined;
/**
* @inheritdoc
*/
validateRpcEndpoint(rpcConfig: UserRpcProviderConfig): Promise<boolean>;
/**
* @inheritdoc
*/
testRpcConnection(rpcConfig: UserRpcProviderConfig): Promise<{
success: boolean;
latency?: number;
error?: string;
}>;
/**
* @inheritdoc
*/
getUiLabels(): Record<string, string> | undefined;
}
/**
* Stellar-specific contract artifacts interface
* Defines the structure of data needed to load Stellar contracts
*/
interface StellarContractArtifacts {
/** The deployed contract ID (required, C...) */
contractAddress: string;
}
/**
* Type guard to check if an object matches StellarContractArtifacts structure
*/
declare function isStellarContractArtifacts(obj: unknown): obj is StellarContractArtifacts;
declare const stellarPublic: StellarNetworkConfig;
declare const stellarTestnet: StellarNetworkConfig;
declare const stellarMainnetNetworks: StellarNetworkConfig[];
declare const stellarTestnetNetworks: StellarNetworkConfig[];
declare const stellarNetworks: StellarNetworkConfig[];
/**
* Configuration for the Stellar adapter
*
* This file defines the dependencies required by the Stellar adapter
* when generating exported projects. It follows the AdapterConfig
* interface to provide a structured approach to dependency management.
*/
declare const stellarAdapterConfig: AdapterConfig;
export { StellarAdapter, type StellarContractArtifacts, isStellarContractArtifacts, stellarAdapterConfig, stellarMainnetNetworks, stellarNetworks, stellarPublic, stellarTestnet, stellarTestnetNetworks };