@synthra-swap/sdk-core v4.2.6
@synthra-swap/sdk-core
โ๏ธ Core SDK for building applications on top of Synthra-swap V3
A robust and type-safe TypeScript SDK that provides the fundamental entities, utilities, and types needed to interact with the Synthra-swap protocol. This package serves as the foundation layer for all other Synthra-swap SDKs.
๐ Features
- Core Entities: Classes for Token, Currency, CurrencyAmount, Price, Fraction, and Percent
- Trading Utilities: Functions for price calculations, address validation, and impact analysis
- Type Safety: Complete TypeScript typing for enhanced development safety
- Multi-Chain Support: Support for Ethereum and compatible networks
- Precise Mathematics: Accurate decimal handling and financial calculations
- Tree Shakable: Modular imports for optimized bundle sizes
๐ฆ Installation
npm install @synthra-swap/sdk-core
yarn add @synthra-swap/sdk-core
pnpm add @synthra-swap/sdk-core
๐ ๏ธ Basic Usage
Importing Entities
import {
Token,
CurrencyAmount,
Price,
Percent,
Fraction
} from '@synthra-swap/sdk-core'
Creating a Token
import { Token, ChainId } from '@synthra-swap/sdk-core'
const USDC = new Token(
ChainId.MAINNET,
'0xA0b86a33E6441c8442a4F5d4c6d8dcFc7a3e9dc5',
6,
'USDC',
'USD Coin'
)
Working with Amounts
import { CurrencyAmount, Token } from '@synthra-swap/sdk-core'
// Create an amount of 100.5 USDC
const amount = CurrencyAmount.fromRawAmount(USDC, '100500000')
// Or from a decimal string
const amountFromString = CurrencyAmount.fromFractionalAmount(
USDC,
'100.5',
'1'
)
console.log(amount.toFixed()) // "100.500000"
Price Calculations
import { Price, Token } from '@synthra-swap/sdk-core'
const price = new Price(
tokenA,
tokenB,
'1000000000000000000', // 1 tokenA
'2000000000000000000' // = 2 tokenB
)
console.log(price.toFixed(4)) // "2.0000"
Working with Percentages
import { Percent } from '@synthra-swap/sdk-core'
// Create a 2.5% percentage
const slippage = new Percent('25', '1000') // 25/1000 = 2.5%
// Or from basis points
const fee = new Percent('30', '10000') // 30 basis points = 0.3%
๐ API Reference
Core Entities
Token
Represents an ERC20 token with its essential properties.
constructor(
chainId: number,
address: string,
decimals: number,
symbol?: string,
name?: string
)
CurrencyAmount
Represents an amount of a specific currency with decimal precision.
static fromRawAmount(currency: Currency, rawAmount: JSBI): CurrencyAmount
static fromFractionalAmount(currency: Currency, numerator: JSBI, denominator: JSBI): CurrencyAmount
Price
Represents the price of one currency in terms of another.
constructor(
baseCurrency: Currency,
quoteCurrency: Currency,
denominator: JSBI,
numerator: JSBI
)
Percent
Extends the Fraction class to represent percentages.
constructor(numerator: JSBI, denominator: JSBI)
Utilities
validateAndParseAddress
Validates and normalizes an Ethereum address.
function validateAndParseAddress(address: string): string
computePriceImpact
Calculates the price impact of a swap.
function computePriceImpact(
midPrice: Price,
inputAmount: CurrencyAmount,
outputAmount: CurrencyAmount
): Percent
๐ Chain Support
The SDK supports the following chains:
- Ethereum Mainnet (ChainId: 1)
- Polygon (ChainId: 137)
- Arbitrum One (ChainId: 42161)
- Optimism (ChainId: 10)
- Base (ChainId: 8453)
๐งช Testing
npm test
The project includes comprehensive tests for all core functionality.
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is released under the MIT License. See the LICENSE file for more details.
๐ Related Resources
Disclaimer: This software is provided "as is" without warranty of any kind. Use at your own risk.wap/sdk-core - Now at Uniswap/sdks
All versions after 4.2.0 of this SDK can be found in the SDK monorepo! Please file all future issues, PRโs, and discussions there.
Old Issues and PRโs
If you have an issue or open PR that is still active on this SDK in this repository, please recreate it in the new repository. Some existing issues and PRโs may be automatically migrated by the Uniswap Labs team.