βοΈ 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.
- 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
npm install @synthra-swap/sdk-coreyarn add @synthra-swap/sdk-corepnpm add @synthra-swap/sdk-coreimport {
Token,
CurrencyAmount,
Price,
Percent,
Fraction
} from '@synthra-swap/sdk-core'import { Token, ChainId } from '@synthra-swap/sdk-core'
const USDC = new Token(
ChainId.MAINNET,
'0xA0b86a33E6441c8442a4F5d4c6d8dcFc7a3e9dc5',
6,
'USDC',
'USD Coin'
)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"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"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%Represents an ERC20 token with its essential properties.
constructor(
chainId: number,
address: string,
decimals: number,
symbol?: string,
name?: string
)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): CurrencyAmountRepresents the price of one currency in terms of another.
constructor(
baseCurrency: Currency,
quoteCurrency: Currency,
denominator: JSBI,
numerator: JSBI
)Extends the Fraction class to represent percentages.
constructor(numerator: JSBI, denominator: JSBI)Validates and normalizes an Ethereum address.
function validateAndParseAddress(address: string): stringCalculates the price impact of a swap.
function computePriceImpact(
midPrice: Price,
inputAmount: CurrencyAmount,
outputAmount: CurrencyAmount
): PercentThe SDK supports the following chains:
- Ethereum Mainnet (ChainId: 1)
- Polygon (ChainId: 137)
- Arbitrum One (ChainId: 42161)
- Optimism (ChainId: 10)
- Base (ChainId: 8453)
npm testThe project includes comprehensive tests for all core functionality.
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
This project is released under the MIT License. See the LICENSE file for more details.
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.
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.