Configuration API ​
Functions and types for configuring Sugar SDK.
getDefaultConfig ​
Creates a default Sugar SDK configuration with sensible defaults. It sets up a wagmi config, enables HTTP batching, and returns a combined config with the sugarConfig property.
Signature ​
function getDefaultConfig(params: {
chains: { chain: Chain; rpcUrl: string }[];
}): SugarWagmiConfigParameters ​
chains- Array of chain configurationschain- Chain object from@wagmi/core/chainsor @dromos-labs/sdk.js exportsrpcUrl- RPC endpoint URL for the chain
Returns ​
SugarWagmiConfig - A combined wagmi + Sugar configuration object
Example ​
import { getDefaultConfig, optimism, base } from "@dromos-labs/sdk.js";
const config = getDefaultConfig({
chains: [
{ chain: optimism, rpcUrl: "https://mainnet.optimism.io" },
{ chain: base, rpcUrl: "https://mainnet.base.org" }
]
});
// Use config throughout your app
const tokens = await getListedTokens({ config });init ​
Attaches Sugar SDK configuration to an existing wagmi config instance. Use it when you need custom wagmi settings, tweaked Sugar parameters, or to integrate an existing wagmi setup.
Signature ​
function init<T extends WagmiCoreConfig>(
wagmiConfig: T,
sugarConfig: Config
): SugarWagmiConfigParameters ​
wagmiConfig- Your wagmi configuration instancesugarConfig- Sugar configuration object (typicallybaseConfigor a customized version)
Returns ​
SugarWagmiConfig - Combined configuration with both wagmi and Sugar settings
Example ​
import { createConfig } from "@wagmi/core";
import { baseConfig, init } from "@dromos-labs/sdk.js";
// Create custom wagmi config
const wagmiConfig = createConfig({
chains: [optimism, base],
transports: {
10: http("https://mainnet.optimism.io"),
8453: http("https://mainnet.base.org"),
},
// ... other wagmi options
});
// Attach Sugar config
const config = init(wagmiConfig, {
...baseConfig,
// Customize Sugar settings
MAX_HOPS: 5,
POOLS_PAGE_SIZE: 500,
});baseConfig ​
Default configuration object with settings for all supported chains.
Type ​
const baseConfig: ConfigProperties ​
DEFAULT_TOKEN_ORDER- Preferred token order for UIsPRICE_THRESHOLD_FILTER- Price threshold valueMAX_HOPS- Maximum routing hops (default: 3)POOLS_PAGE_SIZE- Pools per page (default: 300)TOKENS_PAGE_SIZE- Tokens per page (default: 1000)DEFAULT_CHAIN_ID- Default chain (default: 10 for Optimism)chains- Array of all supported chain configurationstokens- Token-specific configurationsonError- Optional error handler callback
Example ​
import { baseConfig } from "@dromos-labs/sdk.js";
console.log(baseConfig.MAX_HOPS); // 3
console.log(baseConfig.DEFAULT_CHAIN_ID); // 10
console.log(baseConfig.chains.length); // 12
// Customize it
const customConfig = {
...baseConfig,
MAX_HOPS: 5,
onError: (error) => console.error("SDK error:", error),
};Chains ​
Sugar SDK supports the following chains
import {
optimism, // Chain ID 10
unichain, // Chain ID 130
fraxtal, // Chain ID 252
lisk, // Chain ID 1135
metalL2, // Chain ID 1750
soneium, // Chain ID 1868
swellchain, // Chain ID 1923
superseed, // Chain ID 5330
base, // Chain ID 8453
mode, // Chain ID 34443
celo, // Chain ID 42220
ink, // Chain ID 57073
} from "@dromos-labs/sdk.js";supportedChains ​
Array of all chains supported by Sugar SDK (ordered by Chain ID in ascending order):
Type ​
const supportedChains: Chain[]Example ​
import { supportedChains } from "@dromos-labs/sdk.js";
console.log(`Sugar SDK supports ${supportedChains.length} chains`);
supportedChains.forEach(chain => {
console.log(`${chain.name} (${chain.id})`);
});Types ​
Config ​
Main configuration type for Sugar SDK.
type Config = {
readonly DEFAULT_TOKEN_ORDER: string[];
readonly PRICE_THRESHOLD_FILTER: number;
readonly MAX_HOPS: number;
readonly QUOTER_STABLE_POOL_FILLER: number;
readonly QUOTER_VOLATILE_POOL_FILLER: number;
readonly PRICE_MAPS: PriceMap;
readonly POOLS_PAGE_SIZE: number;
readonly TOKENS_PAGE_SIZE: number;
readonly TOKEN_BRIDGE?: Address;
readonly DEFAULT_CHAIN_ID: number;
readonly chains: ReadonlyArray<ChainConfig>;
readonly tokens: { [tokenAddress: Address]: TokenConfig };
onError?: (error: unknown) => void;
};ChainConfig ​
Configuration for a specific blockchain network.
type ChainConfig = {
CHAIN: Chain;
CONNECTOR_TOKENS: Address[];
STABLE_TOKEN: Address;
DEFAULT_TOKENS: Address[];
WRAPPED_NATIVE_TOKEN?: Address;
WETH_ADDRESS?: Address;
UNSAFE_TOKENS?: Address[];
LP_SUGAR_ADDRESS: Address;
REWARDS_SUGAR_ADDRESS: Address;
ROUTER_ADDRESS: Address;
PRICES_ADDRESS: Address;
VOTER_ADDRESS: Address;
QUOTER_ADDRESS: Address;
UNIVERSAL_ROUTER_ADDRESS: Address;
SLIPSTREAM_SUGAR_ADDRESS: Address;
NFPM_ADDRESS: Address;
VE_SUGAR_ADDRESS?: Address;
RELAY_SUGAR_ADDRESS?: Address;
};SugarWagmiConfig ​
Combined Wagmi and Sugar configuration type.
type SugarWagmiConfig = WagmiCoreConfig & {
sugarConfig: Config;
};This is the main config type you'll use throughout the SDK.