Initial commit: add .gitignore and README

This commit is contained in:
defiQUG
2026-02-09 21:51:55 -08:00
commit d904c04c2d
52 changed files with 1613 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
{
"name": "@workspace/blockchain",
"version": "1.0.0",
"description": "Blockchain utilities and helpers",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "vitest",
"lint": "eslint src",
"type-check": "tsc --noEmit",
"clean": "rm -rf dist"
},
"dependencies": {
"ethers": "^6.9.0",
"@workspace/shared-types": "workspace:*"
},
"devDependencies": {
"typescript": "^5.5.4",
"vitest": "^1.2.0"
},
"files": [
"dist"
],
"publishConfig": {
"access": "restricted"
}
}

View File

@@ -0,0 +1,30 @@
/**
* Contract utilities
*/
import { ethers } from 'ethers';
/**
* Get contract instance
*/
export function getContract(
address: string,
abi: ethers.InterfaceAbi,
signerOrProvider: ethers.Signer | ethers.Provider
): ethers.Contract {
return new ethers.Contract(address, abi, signerOrProvider);
}
/**
* Deploy contract
*/
export async function deployContract(
signer: ethers.Signer,
contractFactory: ethers.ContractFactory,
...args: unknown[]
): Promise<ethers.Contract> {
const contract = await contractFactory.deploy(...args);
await contract.waitForDeployment();
return contract;
}

View File

@@ -0,0 +1,51 @@
/**
* Ethers.js utilities
*/
import { ethers } from 'ethers';
/**
* Create provider from RPC URL
*/
export function createProvider(rpcUrl: string): ethers.JsonRpcProvider {
return new ethers.JsonRpcProvider(rpcUrl);
}
/**
* Create wallet from private key
*/
export function createWallet(
privateKey: string,
provider?: ethers.Provider
): ethers.Wallet {
return new ethers.Wallet(privateKey, provider);
}
/**
* Format ether value
*/
export function formatEther(value: bigint): string {
return ethers.formatEther(value);
}
/**
* Parse ether value
*/
export function parseEther(value: string): bigint {
return ethers.parseEther(value);
}
/**
* Format units
*/
export function formatUnits(value: bigint, decimals: number = 18): string {
return ethers.formatUnits(value, decimals);
}
/**
* Parse units
*/
export function parseUnits(value: string, decimals: number = 18): bigint {
return ethers.parseUnits(value, decimals);
}

View File

@@ -0,0 +1,10 @@
/**
* @workspace/blockchain
* Blockchain utilities and helpers
*/
export * from './ethers';
export * from './transactions';
export * from './contracts';
export * from './types';

View File

@@ -0,0 +1,45 @@
/**
* Transaction utilities
*/
import { ethers } from 'ethers';
export interface TransactionOptions {
gasLimit?: bigint;
gasPrice?: bigint;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
value?: bigint;
}
/**
* Wait for transaction confirmation
*/
export async function waitForTransaction(
provider: ethers.Provider,
txHash: string,
confirmations: number = 1
): Promise<ethers.TransactionReceipt | null> {
return provider.waitForTransaction(txHash, confirmations);
}
/**
* Get transaction receipt
*/
export async function getTransactionReceipt(
provider: ethers.Provider,
txHash: string
): Promise<ethers.TransactionReceipt | null> {
return provider.getTransactionReceipt(txHash);
}
/**
* Estimate gas for transaction
*/
export async function estimateGas(
provider: ethers.Provider,
transaction: ethers.TransactionRequest
): Promise<bigint> {
return provider.estimateGas(transaction);
}

View File

@@ -0,0 +1,25 @@
/**
* Blockchain types
*/
export interface NetworkConfig {
name: string;
chainId: number;
rpcUrl: string;
explorerUrl?: string;
}
export interface TokenInfo {
address: string;
symbol: string;
name: string;
decimals: number;
}
export interface TransactionStatus {
hash: string;
status: 'pending' | 'confirmed' | 'failed';
blockNumber?: number;
confirmations: number;
}

View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022"],
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}