1.0.2 • Published 5 months ago

krapow-swap-sdk v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

krapow-swap-sdk.

Official SDK for interacting with the Krapow Protocol on JFIN Chain.

Installation

npm install krapow-swap-sdk.

Features

  • Token swaps (exact and custom amounts)
  • ETH/Token swaps
  • Liquidity management
  • Price calculations and quotes
  • Path finding for optimal trades

Basic Usage

Setup

import { DexSDK, ChainId, Token } from 'krapow-swap-sdk'
import { ethers } from 'ethers'

// Connect to JFIN Chain
const provider = new ethers.providers.JsonRpcProvider(
  'https://rpc.jfinchain.com'
)
const signer = new ethers.Wallet('your-private-key', provider)

// Initialize SDK
const dex = new DexSDK({
  chainId: ChainId.JFIN_MAINNET,
  provider,
  signer,
})

Swap Tokens

// Create token instances
const tokenA = new Token(ChainId.JFIN_MAINNET, '0xTokenAAddress', 18, 'TKNA')
const tokenB = new Token(ChainId.JFIN_MAINNET, '0xTokenBAddress', 6, 'TKNB')

// Perform a swap
const amountIn = ethers.utils.parseEther('1.0')
const tx = await dex.swapExactTokensForTokens(amountIn, tokenA, tokenB, {
  slippageTolerance: 50, // 0.5%
  deadline: Math.floor(Date.now() / 1000) + 60 * 20, // 20 minutes
})

// Wait for confirmation
const receipt = await tx.wait()
console.log(`Swap completed: ${receipt.transactionHash}`)

Provide Liquidity

// Add liquidity
const amountA = ethers.utils.parseEther('10.0')
const amountB = ethers.utils.parseUnits('50.0', 6)

const tx = await dex.addLiquidity(tokenA, tokenB, amountA, amountB)

// Wait for confirmation
const receipt = await tx.wait()

Get Price Information

// Get current price
const price = await dex.getCurrentPrice(tokenA, tokenB)

// Calculate price impact
const priceImpact = await dex.calculatePriceImpact(
  tokenA,
  tokenB,
  ethers.utils.parseEther('1.0')
)

// Get detailed price information
const priceDetails = await dex.getPriceImpactDetails(
  tokenA,
  tokenB,
  ethers.utils.parseEther('1.0')
)

Advanced Features

  • Token pools and pair management
  • ETH/WETH wrapping and unwrapping
  • Pool liquidity calculations
  • Token price discovery
  • Optimal path routing

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

License

ISC License

1.0.2

5 months ago