@varity-labs/types
v2.0.0-alpha.1
Published
Shared TypeScript type definitions for Varity SDK - Multi-chain types, thirdweb integration types
Maintainers
Readme
@varity/types
TypeScript Type Definitions for Varity SDK - Comprehensive types for multi-chain Web3 development, thirdweb integration, and enterprise features.
Installation
npm install @varity/types@alphaQuick Start
import type {
ChainSelection,
ChainMetadata,
EngineTransactionParams,
SmartWalletConfig,
Purchase,
} from '@varity/types';
// Type-safe chain selection
const chainConfig: ChainSelection = {
optimize: 'cost',
requirements: {
testnet: true,
maxGasPrice: BigInt(1000000000)
}
};
// Type-safe transaction parameters
const txParams: EngineTransactionParams = {
chainId: 33529,
to: '0x...',
data: '0x...',
value: 0n,
gasLimit: 100000n
};Features
🔗 Multi-Chain Types
- ChainSelection - Configuration for intelligent chain selection
- ChainMetadata - Chain information with cost/speed/security ratings
- Chain-specific types for Varity L3, Arbitrum, Base
⚡ thirdweb Integration Types
- Engine - Transaction management types (EngineConfig, EngineTransactionParams, EngineWebhookPayload)
- Nebula AI - AI-powered blockchain types (GenerateContractOptions, QueryChainOptions)
- Storage - IPFS/Arweave types (ThirdwebUploadResult, ThirdwebDownloadOptions)
- Bridge - Cross-chain types (BridgeRoute, BridgeQuote, BridgeTransactionResult)
- Gateway - RPC types (RPCRequestOptions, GatewayStats, WebSocketOptions)
- x402 - Payment protocol types (PaymentEndpointConfig, PaymentStats, Subscription)
🔐 Smart Wallet Types
- SmartWalletConfig - ERC-4337 configuration
- GaslessConfig - Paymaster and gas sponsorship
- WalletMetadata - Server wallet management
💳 On-Ramp Types
- Purchase - Payment transaction types
- OnrampWidgetProps - Widget configuration
🎯 SDK Core Types
- VaritySDKConfig - Main SDK configuration
- NetworkConfig - Network settings
- TemplateConfig - Template system types
- StorageOptions - Multi-provider storage
Key Type Exports
Multi-Chain
export interface ChainSelection {
optimize: 'cost' | 'speed' | 'security';
requirements?: {
maxGasPrice?: bigint;
minTPS?: number;
privacy?: 'none' | 'lit' | 'fhe' | 'tee';
testnet?: boolean;
};
}
export interface ChainMetadata {
chain: Chain;
averageGasPrice: bigint;
estimatedTPS: number;
privacyLevel: 'none' | 'lit' | 'fhe' | 'tee';
costRating: number; // 1-10 (1 = cheapest)
speedRating: number; // 1-10 (10 = fastest)
securityRating: number; // 1-10 (10 = most secure)
}thirdweb Engine
export interface EngineConfig {
engineUrl: string;
accessToken: string;
backendWallet: string;
}
export interface EngineTransactionParams {
chainId: number;
to: string;
data: string;
value: bigint;
gasLimit?: bigint;
}
export type EngineTransactionStatus =
| 'queued'
| 'processing'
| 'mined'
| 'errored'
| 'cancelled';
export interface EngineTransactionResult {
queueId: string;
status: EngineTransactionStatus;
transactionHash?: string;
errorMessage?: string;
}Nebula AI
export interface GenerateContractOptions {
prompt: string;
language: 'solidity' | 'vyper';
framework?: 'hardhat' | 'foundry' | 'truffle';
}
export interface QueryChainOptions {
prompt: string;
chainId: number;
includeTransactions?: boolean;
}Storage
export interface ThirdwebUploadResult {
uri: string; // ipfs://... or ar://...
cid: string; // IPFS CID or Arweave transaction ID
size: number; // File size in bytes
gateway: string; // Public gateway URL
}
export interface ThirdwebDownloadOptions {
uri: string;
timeout?: number;
progressCallback?: (progress: number) => void;
}Bridge
export interface BridgeRoute {
fromChain: Chain;
toChain: Chain;
token: string;
estimatedTime: number; // seconds
estimatedFee: bigint;
}
export interface BridgeQuote {
route: BridgeRoute;
amountIn: bigint;
amountOut: bigint;
priceImpact: number; // percentage
validUntil: Date;
}x402 Payment Protocol
export interface PaymentEndpointConfig {
apiUrl: string;
pricePerCall: bigint;
paymentToken: 'USDC' | 'ETH' | 'MATIC';
chain: Chain;
revenueSplit?: {
developer: number; // 70% default
platform: number; // 30% default
};
}
export interface PaymentStats {
totalCalls: number;
totalRevenue: bigint;
developerEarnings: bigint;
platformFee: bigint;
}Smart Wallets
export interface SmartWalletConfig {
chain: Chain;
factoryAddress?: string;
gasless?: {
enabled: boolean;
paymaster?: string | 'auto';
maxGasLimit?: bigint;
};
sessionKeys?: boolean;
}
export interface WalletMetadata {
address: string;
label: string;
encryptedKey: string;
createdAt: Date;
}On-Ramp
export interface Purchase {
id: string;
amount: number;
currency: string;
status: 'pending' | 'processing' | 'completed' | 'failed';
timestamp: Date;
txHash?: string;
}
export interface OnrampWidgetProps {
walletAddress: string;
clientId: string;
defaultAmount?: number;
minAmount?: number;
maxAmount?: number;
onComplete?: (purchase: Purchase) => void;
onError?: (error: Error) => void;
showHistory?: boolean;
theme?: 'light' | 'dark';
}USDC Decimal Handling
CRITICAL: Varity L3 uses USDC with 6 decimals (not 18 like ETH):
// USDC Constants
export const USDC_DECIMALS = 6;
export const VARITY_USDC_ADDRESS = '0x...'; // Actual USDC contract on Varity L3
// Correct USDC formatting
const amount = 1000000n; // 1 USDC = 1,000,000 units (6 decimals)
// Helper functions
export function formatUSDC(amount: bigint): string;
export function parseUSDC(amount: string): bigint;Usage Examples
Type-Safe Chain Selection
import type { ChainSelection, ChainMetadata } from '@varity/types';
const config: ChainSelection = {
optimize: 'speed',
requirements: {
minTPS: 1000,
testnet: false
}
};
function selectChain(config: ChainSelection): ChainMetadata {
// Implementation with full type safety
}Type-Safe thirdweb Engine
import type { EngineTransactionParams, EngineTransactionResult } from '@varity/types';
const params: EngineTransactionParams = {
chainId: 33529,
to: contractAddress,
data: encodedData,
value: 0n
};
const result: EngineTransactionResult = await engine.sendTransaction(params);Type-Safe Smart Wallet
import type { SmartWalletConfig } from '@varity/types';
const walletConfig: SmartWalletConfig = {
chain: varityL3,
gasless: {
enabled: true,
paymaster: 'auto',
maxGasLimit: 500000n
}
};Version
Current version: 2.0.0-alpha.1
License
MIT - See LICENSE file
Documentation
See docs.varity.ai/packages/types for full documentation.
Support
- Documentation: https://docs.varity.ai
- Discord: https://discord.gg/varity
- GitHub Issues: https://github.com/varity-labs/varity-sdk/issues
- Email: [email protected]
