UNPKG

wildcard-sdk

Version:

Node.js SDK for interacting with the Wildcard Deployer contract

530 lines (514 loc) 18.7 kB
import { Signer, ContractTransactionReceipt, ethers, BigNumberish, ContractTransactionResponse } from 'ethers'; import * as viem from 'viem'; import { WalletClient, createPublicClient, Address as Address$1, PublicClient } from 'viem'; import * as react_jsx_runtime from 'react/jsx-runtime'; import { DeepPartial, CandlestickStyleOptions, SeriesOptionsCommon, ChartOptions } from 'lightweight-charts'; type SupportedNetworks = "base-sepolia" | "base-mainnet"; interface EthersSDKConfig { rpcUrl: string; signer?: Signer; privateKey?: string; network: SupportedNetworks; version: "v2" | "v3"; } interface ViemSDKConfig { rpcUrl: string; walletClient?: WalletClient; privateKey?: string; network: SupportedNetworks; version: "v2" | "v3"; } type Address = `0x${string}`; interface FeeSplit$1 { recipient: Address; bps: bigint; } interface PriceCurve { prices: bigint[]; numSteps: bigint; stepSize: bigint; } interface TokenDeploymentConfig { creator: Address; baseToken: Address; name: string; symbol: string; image: string; appIdentifier: string; teamSupply: bigint; vestingStartTime: bigint; vestingDuration: bigint; vestingWallet: Address; bondingCurveSupply: bigint; liquidityPoolSupply: bigint; totalSupply: bigint; bondingCurveBuyFee: bigint; bondingCurveSellFee: bigint; bondingCurveFeeSplits: FeeSplit$1[]; bondingCurveParams: PriceCurve; allowAutoGraduation: boolean; allowForcedGraduation: boolean; graduationFeeBps: bigint; graduationFeeSplits: FeeSplit$1[]; poolFees: number; poolFeeSplits: FeeSplit$1[]; surgeFeeStartingTime: bigint; surgeFeeDuration: bigint; maxSurgeFeeBps: bigint; } interface BuyQuote { amountOut?: bigint; amountInUsed?: bigint; } interface SellQuote { amountOut?: bigint; amountInUsed?: bigint; } type SDKConfig = (EthersSDKConfig & { client: "ethers"; }) | (ViemSDKConfig & { client: "viem"; }); interface TransactionOptions { gasLimit?: bigint; gasPrice?: bigint; value?: bigint; } interface LaunchTokenParams { name: string; symbol: string; image: string; creator: Address; baseToken: Address; totalSupply: string; teamSupply: string; bondingCurveSupply: string; liquidityPoolSupply: string; bondingCurveBuyFee: string; bondingCurveSellFee: string; bondingCurveFeeSplits: FeeSplit$1[]; bondingCurveParams: { prices: string[]; numSteps: string; stepSize: string; }; allowAutoGraduation: boolean; allowForcedGraduation: boolean; graduationFeeBps: string; graduationFeeSplits: FeeSplit$1[]; poolFees: number; poolFeeSplits: FeeSplit$1[]; surgeFeeDuration: string; maxSurgeFeeBps: string; vestingStartTime?: string; vestingDuration?: string; vestingWallet?: Address; protocolFeeBps: number; } interface BuyTokenParams { token: string; amountIn: string; amountOutMin: string; to: string; value?: string; } interface SellTokenParams { token: string; amountIn: string; amountOutMin: string; to: string; } type AutoGraduationParams = { tickSpacing: number; startingTick: number; endTick: number; targetTick: number; poolFee: number; }; type PoolKey = { token0: string; token1: string; fee: number; tickSpacing: number; }; type TokenState = { tokensInBondingCurve: bigint; baseTokensInBondingCurve: bigint; lastPrice?: bigint; totalFees?: bigint; isGraduated: boolean; poolAddress: Address; }; type SwapTokenResult = { success: boolean; transactionHash: string; receipt: ContractTransactionReceipt; }; /** * The breakdown of fees due to a specific recipient address. */ type FeeBreakdown = { /** * Total amount of fee in base token (ETH/USDC etc) due to the address, * both before and after graduation. */ baseTokenFeeShare: string; /** * Total amount of fee in the launched token due to the address, * both before and after graduation. */ tokenFeeShare: string; /** * Base token fee accumulated before the token graduated. */ bondingCurveBaseTokenFee: string; /** * Base token fee accumulated after the token graduated. */ uniswapBaseTokenFee: string; /** * Launched token fee accumulated after the token graduated. */ uniswapTokenFee: string; }; /** * The response object containing fee information for a token. */ type FeeResponse = { /** * The pay split by address to which the fee is due. * Keyed by recipient address. */ tokenFeeShare: Record<string, FeeBreakdown>; /** * The sum total of fees due across all the fee recipient addresses, * accumulated before graduation. */ bondingCurveFeeAccumulated: { baseFee: string; tokenFee: string; }; /** * The sum total of fees due across all the fee recipient addresses, * accumulated after graduation (i.e., in the liquidity pool). */ lpFeeAccumulated: { baseFee: string; tokenFee: string; }; }; declare class DeployerReader { protected contract: ethers.Contract; protected stateManagerContract: ethers.Contract; protected lpLockerContract: ethers.Contract; protected provider: ethers.Provider; private DEPLOYER_ABI; private STATEMANAGER_ABI; private LP_LOCKER_ABI; constructor(config: EthersSDKConfig); getBuyQuote(token: string, amountIn: string): Promise<BuyQuote>; getSellQuote(token: string, amountIn: string): Promise<SellQuote>; getTokenPrice(token: string): Promise<number>; getPredictedTokenAddress(owner: `0x${string}`, salt: `0x${string}`): Promise<{ addr: `0x${string}`; exists: boolean; }>; getOwner(): Promise<string>; isBaseTokenWhitelisted(token: string): Promise<boolean>; getTokenState(token: string): Promise<TokenState>; getProtocolFeeShare(): Promise<number>; getBondingCurveFeeAccumulated(token: string): Promise<string>; getComputerUnclamiedFee(token: string): Promise<string>; getAutoGraduationParams(token: string): Promise<AutoGraduationParams>; getBaseToken(token: string): Promise<string>; getPoolKey(token: string): Promise<PoolKey>; getSurgeFee(config: TokenDeploymentConfig): Promise<string>; getTokenDeploymentConfig(token: string): Promise<TokenDeploymentConfig>; getTokenSupply(token: string): Promise<string>; isGraduated(token: string): Promise<boolean>; getProtocolFeeRecipient(): Promise<string>; getPoolFeeSplits(token: string): Promise<FeeSplit$1[]>; getFees(token: string): Promise<FeeResponse>; getPositionManager(): Promise<string>; getStateView(): Promise<string>; getTokenIdRecipient(): Promise<string>; getTokenDeploymentConfigsMapping(token: string): Promise<TokenDeploymentConfig>; getTokenStatesMapping(token: string): Promise<TokenState>; static formatEther(wei: BigNumberish): string; static parseEther(ether: string): bigint; } declare class DeployerWriter { private contract; private provider; private signer?; private DEPLOYER_ABI; private STATEMANAGER_ABI; constructor(config: EthersSDKConfig); /** * Buy a token by sending base tokens to the bonding curve * @param params Parameters including token address, input amount, minimum output amount, and recipient * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ buyToken(params: BuyTokenParams, options?: TransactionOptions): Promise<SwapTokenResult>; /** * Sell tokens from the bonding curve * @param params Parameters including token address, input amount, minimum output amount, and recipient * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ sellToken(params: SellTokenParams, options?: TransactionOptions): Promise<SwapTokenResult>; /** * Approve the deployer contract to spend a specific token on the user's behalf * @param token ERC20 token address * @param amount Amount to approve * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ approveToken(token: string, amount: string, options?: TransactionOptions): Promise<ContractTransactionResponse>; /** * Approve the deployer contract to spend tokens and then sell them in a single flow * @param params Parameters including token address, input amount, minimum output amount, and recipient * @param options Optional transaction parameters like gas limit and gas price * @returns Sell transaction response */ approveAndSell(params: SellTokenParams, options?: TransactionOptions): Promise<SwapTokenResult>; /** * Claim accumulated bonding curve fees for a specific token * @param token Token address * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ claimFee(token: string, options?: TransactionOptions): Promise<ContractTransactionResponse>; /** * Launch a new token using the bonding curve * @param params Token launch parameters including supplies, fees, and configuration * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response * Protocol fee in basis points (bps). * Required. This fee will automatically be allocated to the protocol. * Example: 500 = 5% */ launchToken(params: LaunchTokenParams, salt?: string, options?: TransactionOptions): Promise<{ tx: ContractTransactionResponse; createdTokenAddress: string; }>; /** * Graduate a token from the bonding curve (can allow forced graduation) * @param token Token address * @param allowPreGraduation Allow forced graduation if true * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ graduateToken(token: string, allowPreGraduation?: boolean, options?: TransactionOptions): Promise<ContractTransactionResponse>; /** * Set the whitelist status of a base token * @param token Token address * @param whitelisted Boolean flag to whitelist (true) or remove from whitelist (false) * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ setBaseTokenWhitelist(token: string, whitelisted: boolean, options?: TransactionOptions): Promise<ContractTransactionResponse>; /** * Relinquish control of the state manager to the protocol * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ relinquishStateManager(options?: TransactionOptions): Promise<ContractTransactionResponse>; /** * Withdraw residual (dust) base tokens from the contract * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response */ withdrawDust(options?: TransactionOptions): Promise<ContractTransactionResponse>; waitForTransaction(txHash: string): Promise<ethers.TransactionReceipt | null>; } declare class EthersDeployer { read: DeployerReader; write: DeployerWriter; constructor(config: EthersSDKConfig); } declare class ViemDeployerReader { protected publicClient: ReturnType<typeof createPublicClient>; protected deployerAddress: Address; protected stateManagerAddress: Address; protected lpLockerAddress: Address; private DEPLOYER_ABI; private STATEMANAGER_ABI; private LP_LOCKER_ABI; constructor(config: ViemSDKConfig); private callDeployer; private callStateManager; private callLpLocker; getBuyQuote(token: string, amountIn: string): Promise<BuyQuote>; getSellQuote(token: string, amountIn: string): Promise<SellQuote>; getTokenPrice(token: Address): Promise<number>; getPredictedTokenAddress(owner: `0x${string}`, salt: `0x${string}`): Promise<{ addr: string; exists: boolean; }>; getOwner(): Promise<string>; isBaseTokenWhitelisted(token: Address): Promise<boolean>; getTokenState(token: Address): Promise<TokenState>; getProtocolFeeShare(): Promise<number>; getBondingCurveFeeAccumulated(token: Address): Promise<string>; getComputeUnclamiedFee(token: Address): Promise<string>; getAutoGraduationParams(token: Address): Promise<AutoGraduationParams>; getBaseToken(token: Address): Promise<string>; getPoolKey(token: Address): Promise<PoolKey>; getSurgeFee(config: TokenDeploymentConfig): Promise<string>; getTokenDeploymentConfig(token: Address): Promise<TokenDeploymentConfig>; getTokenSupply(token: Address): Promise<string>; isGraduated(token: Address): Promise<boolean>; getProtocolFeeRecipient(): Promise<string>; getPoolFeeSplits(token: Address): Promise<FeeSplit$1[]>; getFees(token: Address): Promise<FeeResponse>; getPositionManager(): Promise<string>; getStateView(): Promise<string>; getTokenIdRecipient(): Promise<string>; getTokenDeploymentConfigsMapping(token: Address): Promise<TokenDeploymentConfig>; getTokenStatesMapping(token: Address): Promise<TokenState>; } declare class ViemDeployerWriter { protected config: ViemSDKConfig; protected publicClient: ReturnType<typeof createPublicClient>; protected walletClient: WalletClient; protected deployerAddress: string; protected stateManagerAddress: string; private DEPLOYER_ABI; private STATEMANAGER_ABI; constructor(config: ViemSDKConfig); private buildTxOptions; buyToken(params: BuyTokenParams, options?: TransactionOptions): Promise<{ hash: `0x${string}`; success: "success" | "reverted"; receipt: viem.TransactionReceipt; }>; sellToken(params: SellTokenParams, options?: TransactionOptions): Promise<{ hash: `0x${string}`; success: boolean; receipt: viem.TransactionReceipt; }>; approveToken(token: string, amount: string, options?: TransactionOptions): Promise<`0x${string}`>; approveAndSell(params: SellTokenParams, options?: TransactionOptions): Promise<{ hash: `0x${string}`; success: boolean; receipt: viem.TransactionReceipt; }>; claimFee(token: string, options?: TransactionOptions): Promise<`0x${string}`>; /** * Launch a new token using the bonding curve * @param params Token launch parameters including supplies, fees, and configuration * @param options Optional transaction parameters like gas limit and gas price * @returns Transaction response * Protocol fee in basis points (bps). * Required. This fee will automatically be allocated to the protocol. * Example: 500 = 5% */ launchToken(params: LaunchTokenParams, salt?: string, options?: TransactionOptions): Promise<{ tx: `0x${string}`; createdTokenAddress: string; }>; graduateToken(token: string, allowPreGraduation?: boolean, options?: TransactionOptions): Promise<{ success: boolean; receipt: viem.TransactionReceipt; }>; setBaseTokenWhitelist(token: string, whitelisted: boolean, options?: TransactionOptions): Promise<`0x${string}`>; relinquishStateManager(options?: TransactionOptions): Promise<`0x${string}`>; withdrawDust(options?: TransactionOptions): Promise<`0x${string}`>; waitForTransaction(txHash: `0x${string}`): Promise<viem.TransactionReceipt>; } declare class ViemDeployer { read: ViemDeployerReader; write: ViemDeployerWriter | null; constructor(config: ViemSDKConfig); } type DeployerType<T extends SDKConfig> = T["client"] extends "ethers" ? EthersDeployer : ViemDeployer; declare function useDeployerSDK<T extends SDKConfig>(config: T): { sdk: DeployerType<T> | null; isLoading: boolean; error: Error | null; }; type TradingViewChartProps = { token: string; interval: "1m" | "5m" | "15m" | "1h" | "4h" | "1d" | "1w" | "1M" | "1y"; from?: number; to?: number; chain_id: string; apiUrl?: string; useMockIfEmpty?: boolean; theme?: DeepPartial<CandlestickStyleOptions & SeriesOptionsCommon & ChartOptions>; }; declare function TradingViewChart({ token, interval, from, to, chain_id, apiUrl, useMockIfEmpty, theme, }: TradingViewChartProps): react_jsx_runtime.JSX.Element; interface FeeSplit { bps: number; recipient: string; } interface BondingCurveParams { prices: number[]; numSteps: number; stepSize: number; } interface TokenConfig { name: string; image: string; symbol: string; creator: string; poolFees: number; baseToken: string; teamSupply: number; totalSupply: number; appIdentifier: string; poolFeeSplits: FeeSplit[]; vestingWallet: string; maxSurgeFeeBps: number; vestingDuration: number; graduationFeeBps: number; surgeFeeDuration: number; vestingStartTime: number; bondingCurveBuyFee: number; bondingCurveParams: BondingCurveParams; bondingCurveSupply: number; allowAutoGraduation: boolean; bondingCurveSellFee: number; graduationFeeSplits: FeeSplit[]; liquidityPoolSupply: number; surgeFeeStartingTime: number; allowForcedGraduation: boolean; bondingCurveFeeSplits: FeeSplit[]; } interface TokenData { chain_id: number; token: Address$1; block_number: number; block_timestamp: number; log_index: number; transaction_hash: string; app_id: string; config: TokenConfig; } interface SwapProps { inputToken: TokenData | null; outputToken: TokenData | null; sdk: any; client: PublicClient; WalletConnectButton: React.ComponentType; theme?: Theme; onSwapComplete: (result: { status: string; txHash: string | null; }) => void; } interface Theme { primaryColor?: string; secondaryColor?: string; backgroundColor?: string; textColor?: string; borderColor?: string; secondaryTextColor?: string; btnTextColor?: string; tokenTextColor?: string; loaderColor?: string; } declare function Swap({ inputToken, outputToken, client, sdk, WalletConnectButton, theme, onSwapComplete, }: SwapProps): react_jsx_runtime.JSX.Element; export { Swap, TradingViewChart, useDeployerSDK };