### Local Development Setup for @sodax/sdk Source: https://docs.sodax.com/developers/packages/foundation/sdk Instructions for setting up a local development environment for the SDK, including cloning the repository, installing Node.js v18+, installing dependencies, and making code changes with specific export and import conventions. ```bash pnpm install ``` ```typescript export TS files in same folder index.ts. ``` ```typescript import files using .js postfix. ``` -------------------------------- ### Query Documentation Example Source: https://docs.sodax.com/developers/technical-overview/vault-token Demonstrates how to query the documentation dynamically using an HTTP GET request with an 'ask' query parameter for specific information. ```http GET https://docs.sodax.com/developers/technical-overview/vault-token.md?ask= ``` -------------------------------- ### HTTP GET Request for Documentation Query Source: https://docs.sodax.com/developers/technical-overview/hub-wallet-abstraction This example shows how to query the documentation dynamically using an HTTP GET request with the `ask` query parameter. This is useful for retrieving information not explicitly present on the page. ```http GET https://docs.sodax.com/developers/technical-overview/hub-wallet-abstraction.md?ask= ``` -------------------------------- ### Install @sodax/wallet-sdk-core Source: https://docs.sodax.com/developers/how-to/wallet_providers Install the `@sodax/wallet-sdk-core` package using npm, yarn, or pnpm to get ready-to-use wallet provider implementations. ```bash # Using npm npm install @sodax/wallet-sdk-core ``` ```bash # Using yarn yarn add @sodax/wallet-sdk-core ``` ```bash # Using pnpm pnpm add @sodax/wallet-sdk-core ``` -------------------------------- ### Local Installation of @sodax/sdk Source: https://docs.sodax.com/developers/packages/foundation/sdk Steps to locally install the SDK by cloning the repository, installing dependencies, building the package, and referencing it via a file path in your project's package.json. ```bash cd into repository folder location. pnpm install pnpm run build ``` ```json "@sodax/sdk": "file:/Users/dev/operation-liquidity-layer/sdk-new/packages/sdk" ``` -------------------------------- ### Get Supported Money Market Tokens Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/money_market Retrieve configurations for supported chains and tokens. Use `sodax.initialize()` for dynamic configurations. This example shows how to get supported tokens for a specific chain and all supported tokens. ```typescript import { Sodax, type SpokeChainId, type Token, type Address } from "@sodax/sdk"; const sodax = new Sodax(); await sodax.initialize(); // Initialize for dynamic config (optional) // All supported spoke chains (general config) const spokeChains: SpokeChainId[] = sodax.config.getSupportedSpokeChains(); // Get supported money market tokens for a specific chain const supportedMoneyMarketTokens: readonly Token[] = sodax.moneyMarket.getSupportedTokensByChainId(chainId); // Get all supported money market tokens per chain const allMoneyMarketTokens = sodax.moneyMarket.getSupportedTokens(); // Get all supported reserves (hub chain token addresses, i.e. money market on Sonic chain) const supportedReserves: readonly Address[] = sodax.moneyMarket.getSupportedReserves(); // Check if token address for given spoke chain id is supported (through config service) const isMoneyMarketSupportedToken: boolean = sodax.config.isMoneyMarketSupportedToken(chainId, token); // Alternative: Access through config service const moneyMarketTokensFromConfig: readonly Token[] = sodax.config.getSupportedMoneyMarketTokensByChainId(chainId); const allMoneyMarketTokensFromConfig = sodax.config.getSupportedMoneyMarketTokens(); ``` -------------------------------- ### Install @sodax/wallet-sdk-react Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-react Install the SDK using npm, yarn, or pnpm. ```bash # Using npm npm install @sodax/wallet-sdk-react # Using yarn yarn add @sodax/wallet-sdk-react # Using pnpm pnpm add @sodax/wallet-sdk-react ``` -------------------------------- ### Install @sodax/wallet-sdk-core Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-core Install the package using your preferred package manager. pnpm is recommended. ```bash # Using pnpm (recommended) pnpm add @sodax/wallet-sdk-core # Using npm npm install @sodax/wallet-sdk-core # Using yarn yarn add @sodax/wallet-sdk-core ``` -------------------------------- ### Install @sodax/dapp-kit Source: https://docs.sodax.com/developers/packages/experience/dapp-kit Install the dApp Kit library using npm, yarn, or pnpm. ```bash npm install @sodax/dapp-kit ``` ```bash # or yarn add @sodax/dapp-kit ``` ```bash # or pnpm add @sodax/dapp-kit ``` -------------------------------- ### Query Documentation Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-react Example of how to query the documentation dynamically using a GET request with an 'ask' query parameter. Replace '' with your specific query. ```http GET https://docs.sodax.com/developers/packages/connection/wallet-sdk-react.md?ask= ``` -------------------------------- ### Complete Sodax SDK Example Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api A comprehensive example demonstrating Sodax SDK initialization with custom backend API configuration and usage of various API methods, including error handling. ```typescript import { Sodax } from '@sodax/sdk'; async function example() { // Initialize Sodax with custom backend API configuration const sodax = new Sodax({ backendApiConfig: { baseURL: 'https://api.sodax.com/v1/be', timeout: 60000, headers: { 'Authorization': 'Bearer your-api-token' } } }); try { // Get solver orderbook const orderbook = await sodax.backendApi.getOrderbook({ offset: '0', limit: '5' }); console.log('Orderbook:', orderbook); // Get user's money market position const userAddress = '0x789...ghi'; const position = await sodax.backendApi.getMoneyMarketPosition(userAddress); console.log('User Position:', position); // Get all money market assets const assets = await sodax.backendApi.getAllMoneyMarketAssets(); console.log('Available Assets:', assets); // Get intent by transaction hash const txHash = '0x123...abc'; const intent = await sodax.backendApi.getIntentByTxHash(txHash); console.log('Intent Details:', intent); } catch (error) { console.error('API Error:', error.message); } } example(); ``` -------------------------------- ### Install @sodax/sdk with npm, yarn, or pnpm Source: https://docs.sodax.com/developers/packages/foundation/sdk Use these commands to install the @sodax/sdk package in your project. Choose the package manager you are currently using. ```bash npm install @sodax/sdk ``` ```bash yarn add @sodax/sdk ``` ```bash pnpm add @sodax/sdk ``` -------------------------------- ### Full Fill Fee Example Source: https://docs.sodax.com/developers/technical-overview/intents Illustrates the fee distribution for a full fill scenario. The fee receiver gets the specified fee, and the solver receives the remaining input amount. ```solidity // Intent with 1 ETH input and 0.1 ETH fee FeeData memory feeData = FeeData({ fee: 0.1 ether, receiver: feeReceiver }); // After fill: // - Fee receiver gets 0.1 ETH // - Solver gets 1 ETH ``` -------------------------------- ### Install Dependencies Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-react Installs project dependencies using pnpm. Ensure you have pnpm installed globally. ```bash pnpm install ``` -------------------------------- ### Install Sodax Dapp Kit Dependencies Source: https://docs.sodax.com/developers/packages/experience/dapp-kit Install the necessary packages for Sodax Dapp Kit and React Query using pnpm. ```bash pnpm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk-react ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.sodax.com/developers/technical-overview/generalized-messaging-protocol Perform an HTTP GET request with the `ask` query parameter to dynamically query documentation. The question should be specific and self-contained. ```http GET https://docs.sodax.com/developers/technical-overview/generalized-messaging-protocol.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.sodax.com/developers/packages/experience Perform an HTTP GET request to query the documentation dynamically. Include your question as the `ask` query parameter. The response will contain the answer and relevant excerpts. ```http GET https://docs.sodax.com/developers/packages/experience.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.sodax.com/developers/packages/connection Use this method to dynamically query the documentation. Include your question as the 'ask' query parameter in the GET request. ```http GET https://docs.sodax.com/developers/packages/connection.md?ask= ``` -------------------------------- ### ERC20 to Native Token Intent Example Source: https://docs.sodax.com/developers/technical-overview/intents Example of creating an intent where the input is an ERC20 token and the output is a native token. The `dstChain` must be the hub chain for native token outputs. ```solidity Intent memory intent = Intent({ inputToken: erc20Token, outputToken: address(0), // Native token inputAmount: 1000, minOutputAmount: 1 ether, dstChain: HUB_CHAIN_ID, // Must be hub chain for native token // ... other fields ... }); // Fill intent with native token intents.fillIntent{value: 1 ether}(intent, 1000, 1 ether, 0); ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api To get more information not present on the current page, make an HTTP GET request to the page URL with the `ask` query parameter. The question should be specific and self-contained. ```http GET https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api.md?ask= ``` -------------------------------- ### Dynamic Documentation Query Source: https://docs.sodax.com/developers/deployments/relayer_api_endpoints To get additional information not explicitly present, perform an HTTP GET request with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://docs.sodax.com/developers/deployments/relayer_api_endpoints.md?ask= ``` -------------------------------- ### Run in Development Mode Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-react Starts the project in development mode using pnpm. This typically enables hot-reloading and other development-specific features. ```bash pnpm dev ``` -------------------------------- ### Example DApp: Sending Messages with GMP Source: https://docs.sodax.com/developers/technical-overview/generalized-messaging-protocol Demonstrates how a DApp can initiate cross-chain messages using the `sendMessage` function in the GMP connection contract. ```APIDOC ## Example DApp: Sending Messages with GMP ### Description Demonstrates how a DApp can initiate cross-chain messages using the `sendMessage` function in the GMP connection contract. This allows a DApp to send a signed message to a target contract on another network, which the relayers can then verify and forward to the destination network. ### Code Example ```solidity function gmpAction() external { // Application logic here gmp.sendMessage(targetNetworkID, targetAddress, messagePayload); } ``` ### Parameters * **targetNetworkID** (uint256) - The ID of the target network. * **targetAddress** (bytes) - The address of the target contract on the destination network. * **messagePayload** (bytes) - The payload of the message to be sent. ``` -------------------------------- ### DApp Example: Sending Cross-Chain Messages Source: https://docs.sodax.com/developers/technical-overview/generalized-messaging-protocol Demonstrates how a DApp can initiate cross-chain messages by calling the sendMessage function in the connection contract. ```solidity function gmpAction() external { // Application logic here gmp.sendMessage(targetNetworkID, targetAddress, messagePayload); } ``` -------------------------------- ### Get All Token Information Query Source: https://docs.sodax.com/developers/technical-overview/vault-token Fetches comprehensive information for all supported tokens, including their configurations and current vault reserves. ```solidity function getAllTokenInfo() external view returns ( address[] memory tokens, TokenInfo[] memory infos, uint256[] memory reserves ); ``` -------------------------------- ### Prerequisites for Spoke Provider Creation Source: https://docs.sodax.com/developers/how-to/how_to_create_a_spoke_provider Essential requirements before you can create a spoke provider, including SDK installation and wallet provider setup. ```APIDOC ## Prerequisites Before creating a spoke provider, ensure you have: * A wallet provider implementation for your target chain. You can use existing wallet provider implementations from the [`@sodax/wallet-sdk-core`](https://www.npmjs.com/package/@sodax/wallet-sdk-core) npm package, or use the local package [@wallet-sdk-core](https://github.com/icon-project/sodax-frontend/blob/main/packages/wallet-sdk-core/README.md) if working within the Sodax monorepo. * The `@sodax/sdk` package installed * For Node.js environments: RPC URLs for the chains you're interacting with (we recommend using dedicated node providers like Alchemy, QuickNode, etc.) * For browser environments: Wallet extensions installed and connected (e.g., MetaMask for EVM chains) ``` -------------------------------- ### Sodax Swaps SDK Initialization and Configuration Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/swaps Demonstrates how to initialize the Sodax SDK and access configuration constants for supported chains and tokens. ```APIDOC ## Sodax SDK Initialization and Configuration ### Description Initialize the Sodax SDK to access the latest configurations for supported chains and tokens. By default, the SDK uses configurations from its specific version. ### Code Example ```typescript import { SpokeChainId, Token, Sodax } from "@sodax/sdk"; const sodax = new Sodax(); // Initialize the SDK to fetch dynamic (backend API based) configurations. await sodax.initialize(); // Retrieve all supported spoke chains. const spokeChains: SpokeChainId[] = sodax.config.getSupportedSpokeChains(); // Retrieve supported swap tokens for a specific chain ID. const supportedSwapTokensForChainId: readonly Token[] = sodax.swaps.getSupportedSwapTokensByChainId(spokeChainId); // Retrieve all supported swap tokens across all chains. const supportedSwapTokensPerChain: Record = sodax.swaps.getSupportedSwapTokens(); // Check if a specific token address is supported for swaps on a given chain. const isSwapSupportedToken: boolean = isSwapSupportedToken(spokeChainId, token); ``` ### See Also - [SDK constants.ts](https://github.com/icon-project/sodax-frontend/blob/main/packages/types/src/constants/index.ts) ``` -------------------------------- ### Money Market SDK Initialization and Configuration Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/money_market Demonstrates how to initialize the Sodax SDK for dynamic configuration and access various configuration constants like supported chains and tokens. ```APIDOC ## Initialising Spoke Provider Refer to [Initialising Spoke Provider](https://docs.sodax.com/developers/how-to/how_to_create_a_spoke_provider) section to see how BSC spoke provider used as `bscSpokeProvider` can be created. ## Using SDK Config and Constants SDK includes predefined configurations of supported chains, tokens and other relevant information for the client to consume. All configurations are accessible through the `config` property of the Sodax instance (`sodax.config`), or through service-specific properties for convenience. **IMPORTANT**: If you want dynamic (backend API based - contains latest tokens) configuration, make sure to initialize the instance before usage: ```typescript await sodax.initialize(); ``` By default, configuration from the specific SDK version you are using is used. ```typescript import { Sodax, type SpokeChainId, type Token, type Address } from "@sodax/sdk"; const sodax = new Sodax(); await sodax.initialize(); // Initialize for dynamic config (optional) // All supported spoke chains (general config) const spokeChains: SpokeChainId[] = sodax.config.getSupportedSpokeChains(); // Get supported money market tokens for a specific chain const supportedMoneyMarketTokens: readonly Token[] = sodax.moneyMarket.getSupportedTokensByChainId(chainId); // Get all supported money market tokens per chain const allMoneyMarketTokens = sodax.moneyMarket.getSupportedTokens(); // Get all supported reserves (hub chain token addresses, i.e. money market on Sonic chain) const supportedReserves: readonly Address[] = sodax.moneyMarket.getSupportedReserves(); // Check if token address for given spoke chain id is supported (through config service) const isMoneyMarketSupportedToken: boolean = sodax.config.isMoneyMarketSupportedToken(chainId, token); // Alternative: Access through config service const moneyMarketTokensFromConfig: readonly Token[] = sodax.config.getSupportedMoneyMarketTokensByChainId(chainId); const allMoneyMarketTokensFromConfig = sodax.config.getSupportedMoneyMarketTokens(); ``` Please refer to [SDK constants.ts](https://github.com/icon-project/sodax-frontend/blob/main/packages/types/src/constants/index.ts) for additional static constants and configurations. ``` -------------------------------- ### Quick Start: React Wallet Integration Source: https://docs.sodax.com/developers/packages/connection/wallet-sdk-react Set up SodaxWalletProvider, QueryClientProvider, and use core hooks like useXConnectors, useXConnect, and useXAccount to manage wallet connectivity and display account information. ```typescript import { SodaxWalletProvider, useXConnectors, useXConnect, useXAccount } from '@sodax/wallet-sdk-react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { RpcConfig } from '@sodax/types'; // Create a QueryClient instance const queryClient = new QueryClient(); const rpcConfig: RpcConfig = { // EVM chains sonic: 'https://rpc.soniclabs.com', '0xa86a.avax': 'https://api.avax.network/ext/bc/C/rpc', '0xa4b1.arbitrum': 'https://arb1.arbitrum.io/rpc', '0x2105.base': 'https://mainnet.base.org', '0x38.bsc': 'https://bsc-dataseed1.binance.org', '0xa.optimism': 'https://mainnet.optimism.io', '0x89.polygon': 'https://polygon-rpc.com', // Other chains '0x1.icon': 'https://ctz.solidwallet.io/api/v3', solana: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key', sui: 'https://fullnode.mainnet.sui.io', 'injective-1': 'https://sentry.tm.injective.network:26657', }; function App() { return ( ); } function WalletConnect() { // Get available connectors for EVM chain const connectors = useXConnectors('EVM'); // Get connect mutation const { mutateAsync: connect } = useXConnect(); // Get connected account info const account = useXAccount('EVM'); return (
{/* Display connected wallet address if connected */} {account?.address && (

Connected Wallet:

{account.address}

)} {/* Display available connectors */}
{connectors.map((connector) => ( ))}
); } ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/money_market To get additional information not present on the page, perform an HTTP GET request to the current URL with an 'ask' query parameter containing your specific question. ```http GET https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/money_market.md?ask= ``` -------------------------------- ### Agent Instructions: Querying Documentation Source: https://docs.sodax.com/developers/technical-overview/intents Provides instructions on how to query the documentation dynamically using an HTTP GET request with an 'ask' query parameter. This is useful for retrieving specific information not explicitly present on the page. ```http GET https://docs.sodax.com/developers/technical-overview/intents.md?ask= ``` -------------------------------- ### Initialize SDK and Access Configuration Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/swaps Shows how to initialize the Sodax SDK for dynamic configurations and access supported chains and tokens. Initialization ensures you have the latest token data. ```typescript import { SpokeChainId, Token, Sodax } from "@sodax/sdk"; const sodax = new Sodax(); // if you want dynamic (backend API based - contains latest tokens) configuration make sure to initialize instance before usage! // by default configuration from specific SDK version you are using is used await sodax.initialize(); // all supported spoke chains const spokeChains: SpokeChainId[] = sodax.config.getSupportedSpokeChains(); // using spoke chain id to retrieve supported tokens for swap (solver intent swaps) // NOTE: empty array indicates no tokens are supported, you should filter out empty arrays const supportedSwapTokensForChainId: readonly Token[] = sodax.swaps.getSupportedSwapTokensByChainId(spokeChainId); // object containing all supported swap tokens per chain ID const supportedSwapTokensPerChain: Record = sodax.swaps.getSupportedSwapTokens(); // check if token address for given spoke chain id is supported in swaps const isSwapSupportedToken: boolean = isSwapSupportedToken(spokeChainId, token) ``` -------------------------------- ### Initialize Sodax and Get Quote Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/swaps Demonstrates initializing the Sodax SDK and making a quote request. Ensure the Sodax instance is initialized before use for dynamic configurations. ```typescript import { Sodax, SpokeChainId, Token } from "@sodax/sdk"; const sodax = new Sodax(); // All swap methods are available through sodax.swap const quote = await sodax.swaps.getQuote(quoteRequest); ``` -------------------------------- ### Initialize Sodax SDK with Default Configuration Source: https://docs.sodax.com/developers/how-to/configure_sdk Initializes the SDK with default Sonic mainnet configurations. No additional setup is required for basic usage. ```typescript import { Sodax } from '@sodax/sdk'; const sodax = new Sodax(); ``` -------------------------------- ### Initialize Sodax Instance (Custom Configuration) Source: https://docs.sodax.com/developers/how-to/how_to_make_a_swap Create a Sodax instance with custom solver configuration and hub provider settings. This allows for specific network or RPC endpoint configurations. ```typescript import { Sodax, getSolverConfig, getHubChainConfig, SONIC_MAINNET_CHAIN_ID } from "@sodax/sdk"; const sodax = new Sodax({ swap: getSolverConfig(SONIC_MAINNET_CHAIN_ID), // Custom solver config hubProviderConfig: { hubRpcUrl: 'https://rpc.soniclabs.com', chainConfig: getHubChainConfig(), }, }); await sodax.initialize(); ``` -------------------------------- ### Querying Documentation Dynamically Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/intent_relay_api To get additional information not directly present on the page, perform an HTTP GET request with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/intent_relay_api.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.sodax.com/developers/how-to/stellar_trustline To get more information not present on the current page, you can query the documentation dynamically using an HTTP GET request with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://docs.sodax.com/developers/how-to/stellar_trustline.md?ask= ``` -------------------------------- ### Initialize Sodax Instance (Default Mainnet) Source: https://docs.sodax.com/developers/how-to/how_to_make_a_swap Create and initialize a Sodax instance using default mainnet configurations. Initialization fetches the latest supported tokens and chains from the backend API. ```typescript import { Sodax } from "@sodax/sdk"; // Create Sodax instance (defaults to mainnet configs) const sodax = new Sodax(); // Initialize to fetch latest configuration from the backend API (optional, use version based approach without initialize for more stability) // Initialization fetches the latest configuration from the backend API, including supported tokens and chains. // This ensures you have the most up-to-date token and chain information await sodax.initialize(); ``` -------------------------------- ### Configure Sodax Providers Source: https://docs.sodax.com/developers/packages/experience/dapp-kit Set up the SodaxProvider and QueryClientProvider with RPC configurations for various EVM and other chains. Ensure WalletProvider is nested within QueryClientProvider. ```typescript import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { SodaxWalletProvider } from '@sodax/wallet-sdk-react'; import { SodaxProvider } from '@sodax/dapp-kit'; import type { RpcConfig } from '@sodax/types'; const queryClient = new QueryClient(); const rpcConfig: RpcConfig = { // EVM chains sonic: 'https://rpc.soniclabs.com', '0xa86a.avax': 'https://api.avax.network/ext/bc/C/rpc', '0xa4b1.arbitrum': 'https://arb1.arbitrum.io/rpc', '0x2105.base': 'https://mainnet.base.org', '0x38.bsc': 'https://bsc-dataseed1.binance.org', '0xa.optimism': 'https://mainnet.optimism.io', '0x89.polygon': 'https://polygon-rpc.com', // Other chains '0x1.icon': 'https://ctz.solidwallet.io/api/v3', solana: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key', sui: 'https://fullnode.mainnet.sui.io', 'injective-1': 'https://sentry.tm.injective.network:26657', }; function App() { return ( ); } ``` -------------------------------- ### Example Transfer Data with Staking Action Source: https://docs.sodax.com/developers/technical-overview/hub-wallet-abstraction This Solidity struct example demonstrates how to encode a cross-chain transfer that includes an additional staking action. The `data` field contains encoded contract calls. ```solidity // Example of transfer data that includes staking action Transfer { token: "0x...", // Source chain token address from: userAddress, to: hubWalletAddress, amount: 1000, data: abi.encode( ContractCall({ addr: STAKING_CONTRACT, value: 0, data: abi.encodeWithSignature("stake(uint256)", 1000) }) ) } ``` -------------------------------- ### Common Development Commands for @sodax/sdk Source: https://docs.sodax.com/developers/packages/foundation/sdk A list of essential commands for managing the @sodax/sdk development workflow, including dependency installation, building, running in development mode, type checking, code formatting, and linting. ```bash pnpm install ``` ```bash pnpm build ``` ```bash pnpm dev ``` ```bash pnpm checkTs ``` ```bash pnpm pretty ``` ```bash pnpm lint ``` -------------------------------- ### Query Documentation via API Source: https://docs.sodax.com/developers/how-to/configure_sdk To get additional information not directly present on the page, perform an HTTP GET request to the current page URL with the `ask` query parameter. The question should be specific and in natural language. ```http GET https://docs.sodax.com/developers/how-to/configure_sdk.md?ask= ``` -------------------------------- ### Querying Documentation Dynamically Source: https://docs.sodax.com/developers/packages/foundation/sdk Demonstrates how to perform an HTTP GET request to query the documentation dynamically by appending an 'ask' query parameter with a natural language question. ```http GET https://docs.sodax.com/developers/packages/foundation/sdk.md?ask= ``` -------------------------------- ### GET /staking/getUnstakingInfo Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/staking Retrieves unstaking information for a user. ```APIDOC ## GET /staking/getUnstakingInfo ### Description Retrieves information about the user's current unstaking status and requests. ### Method GET ### Endpoint /staking/getUnstakingInfo ### Parameters #### Query Parameters - **param** (string | object) - Required - Can be the user's address or the spoke provider instance. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the operation was successful. - **value** (UnstakingInfo) - An object containing unstaking details. - **totalUnstaking** (bigint) - The total amount currently being unstaked. - **userUnstakeSodaRequests** (array) - A list of user's unstake requests. #### Error Response (non-200) - **ok** (boolean) - Indicates if the operation was successful (false). - **error** (StakingError<'INFO_FETCH_FAILED'>) - The error object detailing the failure. #### Response Example ```json { "ok": true, "value": { "totalUnstaking": "200000000000000000", "userUnstakeSodaRequests": [ { ... }, { ... } ] } } ``` ``` -------------------------------- ### Get Orderbook Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api Retrieves the solver orderbook with pagination support. ```APIDOC ## GET /solver/orderbook ### Description Retrieves the solver orderbook with pagination support. ### Method GET ### Endpoint /solver/orderbook ### Parameters #### Query Parameters - **offset** (string) - Required - Starting position for pagination - **limit** (string) - Required - Maximum number of items to return ### Response #### Success Response (200) - **total** (number) - The total number of orderbook entries. - **data** (Array) - An array of orderbook entries. - **intentState** (object) - The current state of the intent. - **exists** (boolean) - Indicates if the intent exists. - **remainingInput** (string) - The remaining input amount for the intent. - **receivedOutput** (string) - The output amount received for the intent. - **pendingPayment** (boolean) - Indicates if there is a pending payment for the intent. - **intentData** (object) - The data associated with the intent. - **intentId** (string) - The unique identifier for the intent. - **creator** (string) - The address of the intent creator. - **inputToken** (string) - The address of the input token. - **outputToken** (string) - The address of the output token. - **inputAmount** (string) - The amount of input tokens. - **minOutputAmount** (string) - The minimum output amount expected. - **deadline** (string) - The deadline for the intent. - **allowPartialFill** (boolean) - Whether partial fills are allowed. - **srcChain** (number) - The source chain ID. - **dstChain** (number) - The destination chain ID. - **srcAddress** (string) - The source address. - **dstAddress** (string) - The destination address. - **solver** (string) - The address of the solver. - **data** (string) - Additional data for the intent. - **intentHash** (string) - The hash of the intent. - **txHash** (string) - The transaction hash associated with the intent. - **blockNumber** (number) - The block number where the intent was processed. ### Request Example ```typescript const orderbook = await sodax.backendApi.getOrderbook({ offset: '0', limit: '10' }); ``` ### Response Example ```json { "total": 25, "data": [ { "intentState": { "exists": true, "remainingInput": "1000000000000000000", "receivedOutput": "0", "pendingPayment": false }, "intentData": { "intentId": "intent_123", "creator": "0x789...ghi", "inputToken": "0xabc...123", "outputToken": "0xdef...456", "inputAmount": "1000000000000000000", "minOutputAmount": "950000000000000000", "deadline": "1700000000", "allowPartialFill": true, "srcChain": 146, "dstChain": 1, "srcAddress": "0x789...ghi", "dstAddress": "0x789...ghi", "solver": "0x000...000", "data": "0x", "intentHash": "0x456...def", "txHash": "0x123...abc", "blockNumber": 12345678 } } ] } ``` ``` -------------------------------- ### Combine Sodax SDK Configurations Source: https://docs.sodax.com/developers/how-to/configure_sdk Use this snippet to combine all necessary configurations for the Sodax SDK, including swap, money market, and hub provider settings. Ensure all required imports are present. The `sodax.initialize()` call is optional but recommended for the latest data. ```typescript import { Sodax, getSolverConfig, getMoneyMarketConfig, getHubChainConfig, SONIC_MAINNET_CHAIN_ID, } from '@sodax/sdk'; const sodax = new Sodax({ swap: getSolverConfig(SONIC_MAINNET_CHAIN_ID), moneyMarket: getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID), ..., hubProviderConfig: { hubRpcUrl: 'https://rpc.soniclabs.com', chainConfig: getHubChainConfig(SONIC_MAINNET_CHAIN_ID), }, sharedConfig: { // config used by internal services [STELLAR_MAINNET_CHAIN_ID]: { horizonRpcUrl: 'https://horizon.stellar.org', sorobanRpcUrl: 'https://rpc.ankr.com/stellar_soroban', } } }); // Optional: initialize for latest tokens/chains await sodax.initialize(); ``` -------------------------------- ### GET /staking/getStakingConfig Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/staking Retrieves the current staking configuration from the stakedSoda contract. ```APIDOC ## GET /staking/getStakingConfig ### Description Fetches the global staking configuration parameters from the stakedSoda smart contract. ### Method GET ### Endpoint /staking/getStakingConfig ### Parameters None ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the operation was successful. - **value** (StakingConfig) - An object containing staking configuration details. - **unstakingPeriod** (bigint) - The duration (in seconds) for the unstaking period. - **minUnstakingPeriod** (bigint) - The minimum duration (in seconds) for unstaking. - **maxPenalty** (bigint) - The maximum penalty percentage. #### Error Response (non-200) - **ok** (boolean) - Indicates if the operation was successful (false). - **error** (StakingError<'INFO_FETCH_FAILED'>) - The error object detailing the failure. #### Response Example ```json { "ok": true, "value": { "unstakingPeriod": "2592000", "minUnstakingPeriod": "86400", "maxPenalty": "100" } } ``` ``` -------------------------------- ### Perform HTTP GET Request with 'ask' Parameter Source: https://docs.sodax.com/developers/how-to/monetize_sdk Use this method to query the documentation dynamically. The question should be specific and self-contained. The response will include a direct answer and relevant excerpts. ```HTTP GET https://docs.sodax.com/developers/how-to/monetize_sdk.md?ask= ``` -------------------------------- ### GET /staking/getStakingInfo Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/staking Retrieves comprehensive staking information for a user by their address. ```APIDOC ## GET /staking/getStakingInfo ### Description Retrieves comprehensive staking information for a user based on their provided address. ### Method GET ### Endpoint /staking/getStakingInfo ### Parameters #### Query Parameters - **userAddress** (string) - Required - The user's wallet address. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the operation was successful. - **value** (StakingInfo) - An object containing staking details. - **totalStaked** (bigint) - The total amount staked. - **userXSodaBalance** (bigint) - The user's xSODA balance. - **userXSodaValue** (bigint) - The value of the user's xSODA balance. #### Error Response (non-200) - **ok** (boolean) - Indicates if the operation was successful (false). - **error** (StakingError<'INFO_FETCH_FAILED'>) - The error object detailing the failure. #### Response Example ```json { "ok": true, "value": { "totalStaked": "1000000000000000000", "userXSodaBalance": "500000000000000000", "userXSodaValue": "500000000000000000" } } ``` ``` -------------------------------- ### Initialize SolanaRawSpokeProvider Source: https://docs.sodax.com/developers/how-to/how_to_create_a_spoke_provider Instantiate SolanaRawSpokeProvider using either an RPC URL or an existing Connection instance. Ensure you have the correct chain configuration and user wallet address. ```typescript import { SolanaRawSpokeProvider, SOLANA_MAINNET_CHAIN_ID, spokeChainConfig, type SolanaChainConfig } from "@sodax/sdk"; // User's wallet address (Solana Base58 format) const userWalletAddress = 'EuenpE24dc6ve6STi8enwgXJ6yuR7fgUrFa3KSYHmFTv'; // Get chain configuration const solanaChainConfig = spokeChainConfig[SOLANA_MAINNET_CHAIN_ID] as SolanaChainConfig; // Create raw Solana spoke provider with RPC URL const solanaRawSpokeProvider = new SolanaRawSpokeProvider({ connection: { rpcUrl: 'https://api.mainnet-beta.solana.com' }, walletAddress: userWalletAddress, chainConfig: solanaChainConfig }); // Or with existing Connection instance import { Connection } from "@solana/web3.js"; const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed'); const solanaRawSpokeProviderWithConnection = new SolanaRawSpokeProvider({ connection: { connection }, walletAddress: userWalletAddress, chainConfig: solanaChainConfig }); ``` -------------------------------- ### GET /staking/getUnstakingInfoWithPenalty Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/staking Retrieves unstaking information along with penalty calculations for a user. ```APIDOC ## GET /staking/getUnstakingInfoWithPenalty ### Description Retrieves detailed unstaking information, including penalty calculations for each unstake request. ### Method GET ### Endpoint /staking/getUnstakingInfoWithPenalty ### Parameters #### Query Parameters - **param** (string | object) - Required - Can be the user's address or the spoke provider instance. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the operation was successful. - **value** (object) - An object containing unstaking details and penalty information. - **totalUnstaking** (bigint) - The total amount currently being unstaked. - **userUnstakeSodaRequests** (array) - A list of user's unstake requests. - **requestsWithPenalty** (array) - A list of unstake requests with penalty details. - **request** (object) - Details of the unstake request. - **amount** (bigint) - The amount requested for unstaking. - **penalty** (bigint) - The calculated penalty amount. - **penaltyPercentage** (number) - The penalty percentage. - **claimableAmount** (bigint) - The amount claimable after penalty. #### Error Response (non-200) - **ok** (boolean) - Indicates if the operation was successful (false). - **error** (StakingError<'INFO_FETCH_FAILED'>) - The error object detailing the failure. #### Response Example ```json { "ok": true, "value": { "totalUnstaking": "200000000000000000", "userUnstakeSodaRequests": [ { ... } ], "requestsWithPenalty": [ { "request": {"amount": "100000000000000000"}, "penalty": "10000000000000000", "penaltyPercentage": 10, "claimableAmount": "90000000000000000" } ] } } ``` ``` -------------------------------- ### GET /staking/getStakingInfoFromSpoke Source: https://docs.sodax.com/developers/packages/foundation/sdk/functional-modules/staking Retrieves comprehensive staking information for a user using the spoke provider. ```APIDOC ## GET /staking/getStakingInfoFromSpoke ### Description Retrieves comprehensive staking information for a user by interacting with the spoke chain provider. ### Method GET ### Endpoint /staking/getStakingInfoFromSpoke ### Parameters #### Query Parameters - **spokeProvider** (object) - Required - The spoke chain provider instance. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the operation was successful. - **value** (StakingInfo) - An object containing staking details. - **totalStaked** (bigint) - The total amount staked. - **userXSodaBalance** (bigint) - The user's xSODA balance. - **userXSodaValue** (bigint) - The value of the user's xSODA balance. #### Error Response (non-200) - **ok** (boolean) - Indicates if the operation was successful (false). - **error** (StakingError<'INFO_FETCH_FAILED'>) - The error object detailing the failure. #### Response Example ```json { "ok": true, "value": { "totalStaked": "1000000000000000000", "userXSodaBalance": "500000000000000000", "userXSodaValue": "500000000000000000" } } ``` ``` -------------------------------- ### Get All Money Market Borrowers Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api Retrieves a paginated list of all money market borrowers. ```APIDOC ## GET /moneymarket/borrowers ### Description Retrieves all money market borrowers with pagination. ### Method GET ### Endpoint `/moneymarket/borrowers` ### Parameters #### Query Parameters - **offset** (string) - Required - Starting position for pagination - **limit** (string) - Required - Maximum number of items to return ### Response #### Success Response (200) - **borrowers** (string[]) - List of borrower addresses. - **total** (number) - Total number of borrowers. - **offset** (number) - The offset used for pagination. - **limit** (number) - The limit used for pagination. ### Response Example ```json { "borrowers": [ "0x789...ghi", "0xabc...def", "0x123...456" ], "total": 75, "offset": 0, "limit": 10 } ``` ``` -------------------------------- ### Query Documentation with `ask` Parameter Source: https://docs.sodax.com/welcome-to-sodax/readme-1 Perform an HTTP GET request on a documentation URL with the `ask` query parameter to dynamically query the documentation. The question should be specific and in natural language. Use this when the answer is not explicitly present or requires clarification. ```HTTP GET https://docs.sodax.com/welcome-to-sodax/readme-1.md?ask= ``` -------------------------------- ### Get Asset Suppliers Source: https://docs.sodax.com/developers/packages/foundation/sdk/tooling-modules/backend_api Retrieves a paginated list of suppliers for a specific money market asset. ```APIDOC ## GET /moneymarket/asset/{reserveAddress}/suppliers ### Description Retrieves suppliers for a specific money market asset with pagination. ### Method GET ### Endpoint `/moneymarket/asset/{reserveAddress}/suppliers` ### Parameters #### Path Parameters - **reserveAddress** (string) - Required - Reserve contract address #### Query Parameters - **offset** (string) - Required - Starting position for pagination - **limit** (string) - Required - Maximum number of items to return ### Response #### Success Response (200) - **suppliers** (string[]) - List of supplier addresses. - **total** (number) - Total number of suppliers. - **offset** (number) - The offset used for pagination. - **limit** (number) - The limit used for pagination. ### Response Example ```json { "suppliers": [ "0x789...ghi", "0xabc...def", "0x123...456" ], "total": 150, "offset": 0, "limit": 10 } ``` ```