Tokens & Currencies
The SDK provides several currency and amount primitives that are used throughout — from pool construction to trade building and calldata encoding.
Token
Represents a standard ERC-20 token. The constructor takes chain ID, contract address, decimals, and optional symbol/name.
import { Token, ChainId } from '@hydrexfi/hydrex-sdk';
const USDC = new Token(
ChainId.Base,
'0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
6,
'USDC',
'USD Coin'
);Constructor parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | ChainId | required | The chain this token is deployed on. |
address | string | required | The ERC-20 contract address (checksummed). |
decimals | number | required | Number of decimal places (e.g. 6 for USDC, 18 for WETH). |
symbol | string | optional | Ticker symbol for display purposes. |
name | string | optional | Full token name for display purposes. |
Native / ExtendedNative
Represents the native chain currency (ETH on Base). Use Native.onChain(chainId) to get a cached singleton. Both Native and ExtendedNative wrap to WNATIVE[chainId].
import { Native, ChainId } from '@hydrexfi/hydrex-sdk';
const eth = Native.onChain(ChainId.Base);
// eth.wrapped === WNATIVE[ChainId.Base]BoostedToken
Represents an ERC4626 vault-share token (e.g. a Morpho or Euler position). The vault deposits an underlying token and issues shares. When used in a BoostedRoute, the SDK automatically inserts WRAP/ UNWRAP steps.
import { BoostedToken, ChainId } from '@hydrexfi/hydrex-sdk';
const mwETH = new BoostedToken(
ChainId.Base,
'0xYourVaultAddress',
18,
'mwETH',
'Morpho Wrapped ETH',
WETH // underlying Token
);
// Route with automatic wrap/unwrap
const boostedRoute = new BoostedRoute([pool], USDC, mwETH);BoostedRoute steps
boostedRoute.steps to see the WRAP, SWAP, and UNWRAP sequence the SDK will execute. Each step has a type from BoostedRouteStepType.CurrencyAmount
Wraps a raw token amount (as a string or bigint) with its currency reference. Provides formatting helpers.
import { CurrencyAmount } from '@hydrexfi/hydrex-sdk';
const amount = CurrencyAmount.fromRawAmount(USDC, '1000000'); // 1 USDC
// amount.toSignificant(6) => "1.00000"
// amount.toExact() => "1"Percent
A fraction that renders as a percentage. Used for slippage tolerances, fee tiers, and liquidity percentages. Constructed as new Percent(numerator, denominator).
import { Percent } from '@hydrexfi/hydrex-sdk';
const slippage = new Percent(50, 10_000); // 0.5%
const fee = new Percent(1, 100); // 1%Price
A typed price ratio between two currencies. Carry type information about the base and quote tokens to prevent mixing up price directions.
import { Price } from '@hydrexfi/hydrex-sdk';
const price = new Price({
baseAmount: usdcAmount,
quoteAmount: wethAmount,
});
// price.toSignificant(5)Type Reference
| Type / Class | Description |
|---|---|
Token | ERC-20 token with chainId, address, decimals |
Native | Native ETH; .onChain(chainId) returns a cached singleton instance |
ExtendedNative | Extended native currency; same API as Native |
BoostedToken | ERC4626 vault-share token; extends Token; has .underlying |
CurrencyAmount<T> | Amount + currency; .fromRawAmount(), .fromFractionalAmount() |
Percent | Fraction rendered as %; extends Fraction |
Price<Base,Quote> | Typed price between two currencies |
Fraction | Arbitrary precision ratio; base class for Percent / Price |
Currency | Union: NativeCurrency | Token | BoostedToken |
AnyToken | Token | BoostedToken |
BigintIsh | string | number | JSBI — accepted anywhere a raw amount is needed |