TITLE: Execute a UTXO Swap Transaction with Exact Input DESCRIPTION: This asynchronous function initiates an actual swap on the UTXO Swap protocol. It requires a `signTxFunc` (your transaction signing function), a `slippage` tolerance (defaulting to 0.5%), and a minimum CKB fee rate. The function returns the transaction hash upon successful execution of the swap. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_8 LANGUAGE: typescript CODE: ``` const intentTxHash = await pool.swapWithExactInput( signTxFunc, // transaction sign function slippage, // default 0.5, 1-100 5000 // CKB fee rate, must equal to or greater than 5000 ); ``` ---------------------------------------- TITLE: Import and Initialize Core UTXO Swap SDK Components DESCRIPTION: This TypeScript snippet demonstrates how to import essential classes like `Collector`, `Token`, `Client`, and `Pool` from the SDK. It then initializes a `Collector` for CKB on-chain data queries and a `Client` for interacting with the UTXO Swap backend service, using an API key for authentication. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_4 LANGUAGE: typescript CODE: ``` import { Collector, Token, Client, Pool } from '@utxoswap/swap-sdk-js'; /// for CKB on chain query const collector = new Collector({ ckbIndexerUrl }); /// for utxo swap backend service const apiKey = "your api key" const client = new Client(false, apiKey); ``` ---------------------------------------- TITLE: Calculate Expected Output Amount and Price Impact for Swap DESCRIPTION: This TypeScript code uses the `Pool` instance to simulate a swap and determine the expected output amount and the associated price impact. The `calculateOutputAmountAndPriceImpactWithExactInput` method takes the desired input value and returns the calculated output, helping users understand the trade's potential outcome before execution. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_7 LANGUAGE: typescript CODE: ``` const { output } = pool.current.calculateOutputAmountAndPriceImpactWithExactInput( inputValue ); ``` ---------------------------------------- TITLE: Instantiate a UTXO Swap Pool Object DESCRIPTION: This snippet demonstrates the creation of a `Pool` instance, which represents a specific liquidity pool on UTXO Swap. It requires various parameters including token information, the user's CKB address, and the previously initialized `collector` and `client` instances, along with the `poolInfo` retrieved from the backend. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_6 LANGUAGE: typescript CODE: ``` const pool = new Pool({ tokens, ckbAddress: address, collector, client, poolInfo, }); ``` ---------------------------------------- TITLE: Install UTXO Swap SDK Package DESCRIPTION: This command adds the official UTXO Swap SDK package to your project's dependencies. It's the first step to integrate the SDK into your application, making its functionalities available for import and use. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_3 LANGUAGE: bash CODE: ``` $ yarn add @utxoswap/swap-sdk-js ``` ---------------------------------------- TITLE: Retrieve Existing Liquidity Pools from UTXO Swap Backend DESCRIPTION: This asynchronous TypeScript code snippet shows how to fetch a list of existing liquidity pools. It uses the initialized `client` instance to call `getPoolsByToken`, providing pagination parameters and a search key to filter the results, typically by a token's type hash. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_5 LANGUAGE: typescript CODE: ``` const { list: pools } = await client.getPoolsByToken({ pageNo: 0, pageSize: 10, searchKey: "0x0000000000000000000000000000000000000000000000000000000000000000", }); ``` ---------------------------------------- TITLE: Configure ESLint parserOptions for Type-Aware Linting in JavaScript DESCRIPTION: This snippet demonstrates how to configure the 'parserOptions' property within an ESLint configuration file. It sets the ECMAScript version, source type, and specifies paths to TypeScript configuration files ('tsconfig.json', 'tsconfig.node.json') relative to the ESLint config, enabling type-aware linting rules for TypeScript projects. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/example/README.md#_snippet_0 LANGUAGE: JavaScript CODE: ``` export default { // other rules... parserOptions: { ecmaVersion: 'latest', sourceType: 'module', project: ['./tsconfig.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, }, } ``` ---------------------------------------- TITLE: Build and Link UTXO Swap SDK for Local Development DESCRIPTION: These commands compile the TypeScript source code of the UTXO Swap SDK into JavaScript. The `yarn link` command then creates a symbolic link, allowing the SDK to be used locally by other projects, such as the provided example application, without publishing it to a registry. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_1 LANGUAGE: bash CODE: ``` $ yarn build $ yarn link ``` ---------------------------------------- TITLE: Run UTXO Swap SDK Example Application DESCRIPTION: These commands navigate into the example directory, install its specific dependencies, and link the locally built UTXO Swap SDK. Finally, `yarn dev` starts the development server, launching the example application for testing and demonstration purposes. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_2 LANGUAGE: bash CODE: ``` $ cd example/ $ yarn $ yarn link @utxoswap/swap-sdk-js $ yarn dev ``` ---------------------------------------- TITLE: Install Example Project Dependencies DESCRIPTION: This command installs all required Node.js packages for the UTXO Swap SDK example project. It prepares the environment for building and running the demonstration application. SOURCE: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md#_snippet_0 LANGUAGE: bash CODE: ``` $ yarn ```