square-codeBolt Solana TypeScript SDK

Integrate with Bolt Liquidity Protocol using TypeScript.

Overview

The Bolt TypeScript SDK enables seamless integration with the Bolt Liquidity Protocol across multiple blockchain networks. Built with extensibility in mind, this SDK provides developers with a comprehensive, type-safe interface to access all protocol functionality including price feeds, token swaps, liquidity management, and pool operations.

Quickstart

1

Prerequisites

Before using the SDK, make sure you have:

2

Installation

npm install @bolt-liquidity-hq/solana-client
3

Initialize the Bolt Client

The SDK supports different environments:

type Environment = 'mainnet' | 'devnet';
import { BoltSolanaClient } from '@bolt-liquidity-hq/solana-client';

const client = new BoltSolanaClient();
4

Query all assets

// Get all supported assets
const assets = await client.getAssets();
assets.forEach((asset) => {
  console.log(`${asset.symbol} (${asset.name}): ${asset.denom}`);
  console.log(`  Decimals: ${asset.decimals}`);
});

// Find a specific asset
const solAsset = assets.find((a) => a.symbol === 'SOL');
console.log(`SOL type: ${solAsset?.denom}`); // "So11111111111111111111111111111111111111112"
5

Execute a swap

// Get signer from wallet (implementation depends on wallet)
const signer: Signer = await getSolanaWalletSigner();

// Execute a swap: exactly 1 SOL for USDC
const result = await client.swap({
  assetIn: 'So11111111111111111111111111111111111111112',
  amountIn: '1000000000', // 1 SOL (9 decimals)
  assetOut: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
  minimumAmountOut: '1900000', // Minimum 1.9 USDC (6 decimals)
}, signer);

console.log(`Swapped 1 SOL for ${result.amountOut} USDC`);
console.log(`Transaction digest: ${result.txHash}`);
console.log(`Gas cost: ${result.txOutput.effects.gasUsed.computationCost}`);
console.log(`Status: ${result.txOutput.effects.status.status}`);

API

Client Initialization

import { BoltSolanaClient } from '@bolt-liquidity-hq/solana-client';

// Initialize client
const client = new BoltSolanaClient({
  environment: 'mainnet', // 'devnet' | 'mainnet'
  customOverride: {
    chainConfig: {
      rpcEndpoint: 'https://my-custom-rpc-endpoint...', // Remove this if you want to use the default public RPC endpoint
    }
  }
});
chevron-rightAdvanced client initializationhashtag

Environment configuration

Parameter
Type
Default
Description

environment

mainnet | devnet

mainnet

Specifies to which network to connect.

Override chain configuration

Parameter
Type
Default (mainnet)
Default (devnet)
Description

chainConfig.id

string

5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d

EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG

Chain identifier

chainConfig.name

string

Solana

Solana Devnet

Human-readable chain name

chainConfig.websocketEndpoint

string

wss://api.mainnet-beta.solana.com

wss://api.devnet.solana.com

Websocket endpoint URL

Override Outpost contract address

Parameter
Type
Default (mainnet)
Description

contracts.oracle

string

TBD

Oracle contract address

contracts.router

string

TBD

Outpost contract address

Override Oracle PDA

Parameter
Type
Default (mainnet)
Description

oraclePda

string

TBD

Oracle PDA

Override assets configuration

Parameter
Type
Description

assetsConfig

Record<string, Asset>

Custom asset configurations indexed by denomination

Override Solana RPC API client

Parameter
Type
Description

solanaRpcApi

Rpc<SolanaRpcApi>

Pre-existing SolanaRpcApi instance to use for blockchain interactions

Get oracle config

circle-info

getOracleConfig()

The getOracleConfig method retrieves the current configuration settings from the Bolt Liquidity Protocol's Oracle smart contract on the Solana blockchain. This configuration governs how price feeds are managed, including update thresholds, expiration times, and administrative settings.

Usage example

Integration Examples

chevron-rightHow to cache Oracle config (best practice)hashtag
chevron-rightHow to monitor for price updateshashtag

Query prices and assets

circle-info

getAssets()

Retrieves all unique assets available in the Bolt protocol by querying oracle asset pairs and enriching them with additional metadata from the client's asset configuration.

Usage example

circle-info

getAllOracleAssetPairs()

Queries the oracle smart contract to retrieve all supported asset pairs with automatic pagination handling. Each asset pair represents a base/quote relationship that can be used for price queries and swaps.

Usage example

circle-info

getAllPrices()

Queries the oracle smart contract to retrieve all available price feeds with automatic pagination. More efficient than making multiple individual price queries when you need prices for multiple pairs.

Usage example

circle-info

getPrice()

Queries the oracle smart contract to retrieve the current price for a specific asset pair. Fetches the latest price feed that is updated by authorized price feeders and validated against configured thresholds.

Usage example

Verify pool liquidity

circle-info

getPoolBaseLiquidity()

Queries the router smart contract to retrieve the total base asset liquidity across all pools with automatic pagination. Fetches current liquidity levels for all base assets in their respective pools.

Usage example

circle-info

getAllBaseAssetsLiquidity()

Queries the router smart contract to retrieve the base asset liquidity across all pools. Fetches current liquidity levels for all the base assets in their respective pools.

Usage example

Get liquidity pools information

circle-info

getAllPools()

Queries the router smart contract to retrieve information about all deployed pools with automatic pagination. Fetches a comprehensive list of all pools in the Bolt protocol.

Usage example

circle-info

getPoolConfig()

Retrieves the configuration settings of a liquidity pool contract. Queries the contract to fetch its current configuration parameters including fees, LP settings, and oracle integration.

Usage example

circle-info

getPoolByDenom()

Queries the router smart contract to retrieve pool information for a specific base asset on the Archway Blockchain, or a specific base/quote asset pair on the Solana Blockchain. Fetches pool details for the pool matching the provided asset denom(s).

Usage example

circle-info

getPoolConfigByDenom()

Retrieves the configuration settings of a liquidity pool contract identified by its base asset on the Archway Blockchain, or by the base/quote asset pair on the Solana Blockchain. This is a convenience function that combines pool lookup and configuration retrieval.

Usage example

Simulate a swap

circle-info

getRouterConfig()

Simulates a swap operation to calculate the expected output amount without executing the transaction. Performs a dry run of the swap, taking into account current pool conditions, oracle prices, and fees. It's useful for getting accurate estimates before executing a swap.

Usage example

How to execute a swap

circle-info

swap()

The swap method executes a token swap transaction on the Bolt Liquidity Protocol through the router contract. It performs a "swap exact in" operation where users specify exactly how much of the input asset they want to swap, and receive a variable amount of the output asset based on current pool conditions.

Basic usage examples

chevron-rightSimple swaphashtag
chevron-rightSwap with minimum amount out limithashtag
chevron-rightSwap with custom receiverhashtag

Best practices

chevron-rightPrice slippage protectionhashtag
chevron-rightError handling and retrieshashtag
chevron-rightGas estimation and optimizationhashtag

Error Handling

The SDK provides custom error types for better error handling:

  • NotFoundError - Resource not found

  • InvalidParameterError - Invalid parameter provided

  • InvalidObjectError - Invalid object structure

  • InvalidTypeError - Invalid type provided

  • MissingParameterError - Required parameter missing

  • TransactionFailedError - Transaction execution failed

  • ParseError - Failed to parse response data