### Install DeDust SDK Package Source: https://docs.dedust.io/reference/getting-available-pools/docs/getting-started After setting up the core TON prerequisites, install the DeDust SDK package itself. This package provides all the necessary tools and interfaces to interact with the DeDust Protocol. ```Yarn yarn add @dedust/sdk ``` ```NPM npm install --save @dedust/sdk ``` ```PNPM pnpm add @dedust/sdk ``` -------------------------------- ### Install Core TON Prerequisites for DeDust SDK Source: https://docs.dedust.io/reference/getting-available-pools/docs/getting-started Before installing the DeDust SDK, ensure the core TON libraries are added to your project. These libraries provide essential functionalities for interacting with the TON blockchain, which the DeDust SDK relies upon. ```Yarn yarn add @ton/core @ton/ton @ton/crypto ``` ```NPM npm install --save @ton/core @ton/ton @ton/crypto ``` ```PNPM pnpm add @ton/core @ton/ton @ton/crypto ``` -------------------------------- ### Initialize DeDust SDK Factory Contract in TypeScript Source: https://docs.dedust.io/reference/getting-available-pools/docs/getting-started Initialize the DeDust SDK by creating a TonClient4 instance and opening the Factory contract. The Factory contract serves as the central hub for locating and interacting with other DeDust protocol contracts on the TON blockchain. ```TypeScript import { Factory, MAINNET_FACTORY_ADDR } from '@dedust/sdk'; import { Address, TonClient4 } from "@ton/ton"; const tonClient = new TonClient4({ endpoint: "https://mainnet-v4.tonhubapi.com" }); const factory = tonClient.open(Factory.createFromAddress(MAINNET_FACTORY_ADDR)); ``` -------------------------------- ### Create a Volatile Pool with DeDust SDK (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/adding-new-jettons This TypeScript example illustrates how to create a volatile pool between two assets (e.g., TON and SCALE) using the DeDust SDK. It first checks the pool's deployment status and, if not deployed, proceeds to send a `createVolatilePool` message to the factory. This step is essential for enabling trading between the specified jettons. ```TypeScript import { Asset, PoolType, ReadinessStatus } from '@dedust/sdk'; /* ... */ const TON = Asset.native(); const SCALE = Asset.jetton(SCALE_ADDRESS); const pool = tonClient.open( await factory.getPool(PoolType.VOLATILE, [TON, SCALE]), ); const poolReadiness = await pool.getReadinessStatus(); if (poolReadiness === ReadinessStatus.NOT_DEPLOYED) { await factory.sendCreateVolatilePool(sender, { assets: [TON, SCALE], }); } ``` -------------------------------- ### DeDust API: Get Available Pools Endpoint Source: https://docs.dedust.io/reference/getting-available-pools/reference/getting-available-pools This API endpoint allows users to retrieve a comprehensive list of all available liquidity pools on the DeDust protocol. It is a standard GET request to the specified URL. ```APIDOC get https://api.dedust.io/v2/pools ``` -------------------------------- ### Attach Custom Payload for Fulfilled Swaps in DeDust SDK (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/building-advanced-mechanics This example shows how to include a custom payload (`fulfillPayload`) that is sent when a swap is successfully executed. This payload serves as `forward_payload` for jetton transfers or as a payload in the `payout` message for TON, enabling further chained actions upon successful completion. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, fulfillPayload: CUSTOM_PAYLOAD, }, }); ``` -------------------------------- ### Prepare input for DeDust liquidity deposit (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/liquidity-provisioning This step prepares the necessary asset amounts and types (TON and SCALE jetton) required for depositing liquidity into a DeDust pool. It uses `toNano` for amount conversion and `Asset.native()` or `Asset.jetton()` to define the assets. ```TypeScript import { Asset } from '@dedust/sdk'; /* ... */ const tonAmount = toNano("5"); // 5 TON const scaleAmount = toNano("10"); // 10 SCALE const TON = Asset.native(); const SCALE = Asset.jetton(SCALE_ADDRESS); const assets: [Asset, Asset] = [TON, SCALE]; const targetBalances: [bigint, bigint] = [tonAmount, scaleAmount]; ``` -------------------------------- ### Deposit SCALE to DeDust Jetton Vault (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/liquidity-provisioning This snippet shows how to deposit a jetton (SCALE) into its corresponding DeDust jetton vault. It involves opening the jetton root and wallet, then sending a `sendTransfer` transaction to the vault address with a `VaultJetton.createDepositLiquidityPayload` as the forward payload. ```TypeScript import { JettonRoot, PoolType, VaultJetton } from '@dedust/sdk'; /* ... */ const scaleRoot = tonClient.open(JettonRoot.createFromAddress(SCALE_ADDR)); const scaleWallet = tonClient.open(await scaleRoot.getWallet(sender.address)); await scaleWallet.sendTransfer(sender, toNano('0.5'), { amount: scaleAmount, destination: scaleVault.address, responseAddress: sender.address, forwardAmount: toNano('0.4'), forwardPayload: VaultJetton.createDepositLiquidityPayload({ poolType: PoolType.VOLATILE, assets, targetBalances, }), }); ``` -------------------------------- ### Create a Jetton Vault with DeDust SDK (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/adding-new-jettons This TypeScript snippet demonstrates how to create a new vault for a specific jetton using the DeDust SDK. A vault is a prerequisite for any jetton to interact with the DeDust Protocol. The code parses the jetton's address and then calls `sendCreateVault` on the factory contract. ```TypeScript // Address of a new jetton const jettonAddress = Address.parse('EQBlqsm144Dq6SjbPI4jjZvA1hqTIP3CvHovbIfW_t-SCALE'); // Create a vault await factory.sendCreateVault(sender, { asset: Asset.jetton(jettonAddress), }); ``` -------------------------------- ### Find Pools for Multi-Hop Swaps with DeDust SDK in TypeScript Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps This code block illustrates the initial step for a multi-hop swap: defining the assets involved (SCALE, TON, BOLT) and then retrieving the necessary volatile pools (TON-SCALE, TON-BOLT) from the DeDust factory using the `getPool` method. ```TypeScript /* ... */ const SCALE = Asset.jetton(SCALE_ADDRESS); const TON = Asset.native(); const BOLT = Asset.jetton(BOLT_ADDRESS); const TON_SCALE = tonClient.open(await factory.getPool(PoolType.VOLATILE, [TON, SCALE])); const TON_BOLT = tonClient.open(await factory.getPool(PoolType.VOLATILE, [TON, BOLT])); ``` -------------------------------- ### Withdraw liquidity from DeDust pool (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/liquidity-provisioning This code demonstrates how to withdraw liquidity from a DeDust pool by burning LP tokens. It opens the specific pool and the LP token wallet, then sends a `sendBurn` transaction to burn the entire balance of LP tokens held by the sender. ```TypeScript const pool = tonClient.open(await factory.getPool(PoolType.VOLATILE, [TON, SCALE])); const lpWallet = tonClient.open(await pool.getWallet(sender.address)); await lpWallet.sendBurn(sender, toNano('0.5'), { amount: await lpWallet.getBalance(), }); ``` -------------------------------- ### Deposit TON to DeDust Native Vault (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/liquidity-provisioning This code snippet demonstrates how to deposit TON (native asset) into the DeDust native vault. It opens the TON vault using the factory and sends a `sendDepositLiquidity` transaction with the specified pool type, assets, target balances, and TON amount. ```TypeScript import { PoolType } from '@dedust/sdk'; /* ... */ const tonVault = tonClient.open(await factory.getNativeVault()); await tonVault.sendDepositLiquidity(sender, { poolType: PoolType.VOLATILE, assets, targetBalances, amount: tonAmount, }); ``` -------------------------------- ### DeDust Vault Concept and Implementations Source: https://docs.dedust.io/reference/getting-available-pools/docs/concepts Describes the Vault as a class of contracts, each implementing a specific API for interacting with distinct asset types. It details current implementations (Native Vault, Jetton Vault) and an upcoming one (Extra-Currency Vault), explaining their role in handling transfers and informing the Pool. ```APIDOC Vault: Description: A class of contracts, each implementing a specific API tailored for interacting with a distinct asset type. Implementations: - Native Vault: Handles the native coin (Toncoin). - Jetton Vault: Manages jettons. - Extra-Currency Vault (upcoming): Designed for TON extra-currencies. Interaction: - Accepts incoming transfers. - Informs Pool: "user A wants to swap 100 X to Y" (while holding received 100 X). - Pool informs another Vault (for asset Y) to payout Y to user. ``` -------------------------------- ### Common Type: SwapStepParams Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for `SwapStepParams`, extra parameters relevant for a specific swap step. It includes the swap kind, a minimum output limit, and an optional reference to the next step for multi-hop swaps. ```TL-B step_params#_ kind:SwapKind limit:Coins next:(Maybe ^SwapStep) = SwapStepParams; ``` ```APIDOC kind: SwapKind (optional) - Note: Only `given_in` option is implemented. limit: Coins (optional) - Minimum output of the swap. If the actual value is less than specified, the swap will be rejected. next: Maybe ^SwapStep (optional) - Reference to the next step. Can be used for multi-hop swaps. ``` -------------------------------- ### Pool API: estimate_swap_out Source: https://docs.dedust.io/reference/getting-available-pools/reference/pool Estimates the expected output amount and associated trade fee for a given input asset and amount. This helps users predict the outcome of a swap before execution. ```APIDOC estimate_swap_out(asset_in: slice (Asset), amount_in: int): Inputs: asset_in: slice (Asset) amount_in: int Returns: asset_out: slice (Asset) amount_out: int - amount of asset_out trade_fee: int - amount of asset_in asset given as a fee. ``` -------------------------------- ### DeDust Pool Message: Swap Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'swap' message structure for general DeDust pools, used to initiate a token swap. It includes a query ID, the amount of TON for the swap, and a set of swap-specific parameters. ```TL-B swap#ea06185d query_id:uint64 amount:Coins _:SwapStep swap_params:^SwapParams = InMsgBody; Parameters: query_id: uint64 (Required: no) - Query ID amount: Coins (Required: yes) - TON amount for the swap swap_params: ^SwapParams (Required: yes) - Set of parameters relevant for the entire swap ``` -------------------------------- ### Jetton Vault Message: Swap Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'swap' message structure specifically for Jetton Vaults. This message is part of the ForwardPayload and includes swap-specific parameters. ```TL-B swap#e3a0d482 _:SwapStep swap_params:^SwapParams = ForwardPayload; Parameters: swap_params: ^SwapParams (Required: yes) - ``` -------------------------------- ### Pool Event: Swap Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'swap' event structure, an external message (ExtOutMsgBody) used for indexing pool swap activities. It captures details like assets involved, amounts, sender, referral, and updated reserves. ```TL-B swap#9c610de3 asset_in:Asset asset_out:Asset amount_in:Coins amount_out:Coins ^[ sender_addr:MsgAddressInt referral_addr:MsgAddress reserve0:Coins reserve1:Coins ] = ExtOutMsgBody; Parameters: asset_in: Asset (Required: yes) - The asset provided by the user. asset_out: Asset (Required: yes) - The asset received by the user. amount_out: Coins (Required: yes) - Amount of `asset_out` received by the user. amount_in: Coins (Required: yes) - Amount of `asset_in` supplied by the user. sender_addr: MsgAddressInt (Required: yes) - Address of the contract that initiated the swap. referral_addr: MsgAddress (Required: no) - Referral address. Required for the Referral Program. reserve0: Coins (Required: yes) - Amount of `asset0` remaining in reserve after the swap. reserve1: Coins (Required: yes) - Amount of `asset1` remaining in reserve after the swap. ``` -------------------------------- ### Find the TON Vault Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Locates the native TON Vault contract using the DeDust SDK factory, which is essential for initiating native coin swap operations. ```TypeScript import { Asset, VaultNative } from '@dedust/sdk'; // ... // NOTE: We will use tonVault to send a message. const tonVault = tonClient.open(await factory.getNativeVault()); ``` -------------------------------- ### Transfer Jettons to Vault (SCALE) with Swap Payload in TypeScript Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps This snippet demonstrates how to send a specific amount of jettons (SCALE) to a vault address. It includes setting the destination, response address for gas return, forward amount, and a `VaultJetton.createSwapPayload` for a single-hop swap operation. ```TypeScript // ... const amountIn = toNano('50'); // 50 SCALE await scaleWallet.sendTransfer(sender, toNano("0.3"), { amount: amountIn, destination: scaleVault.address, responseAddress: sender.address, // return gas to user forwardAmount: toNano("0.25"), forwardPayload: VaultJetton.createSwapPayload({ poolAddress }), }); ``` -------------------------------- ### Find the SCALE Jetton Vault Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Locates the specific jetton vault for SCALE tokens using the DeDust SDK factory. This is a necessary first step when performing swap operations involving jettons. ```TypeScript const scaleVault = tonClient.open(await factory.getJettonVault(SCALE_ADDRESS)); ``` -------------------------------- ### DeDust Pool Concept and Implementations Source: https://docs.dedust.io/reference/getting-available-pools/docs/concepts Explains the Pool as a class of contracts responsible for curve mathematics and tracking reserves. It outlines the two main implementations: Volatile Pool (Constant Product) and Stable-Swap Pool, including their respective formulas. ```APIDOC Pool: Description: A class of contracts that follow the Pool API, handling curve mathematics and tracking reserves. Implementations: - Volatile Pool: Formula: x * y = k (Constant Product) - Stable-Swap Pool: Optimization: For assets of near-equal value (e.g., USDT/USDC, TON/stTON). Formula: x3 * y + y3 * x = k ``` -------------------------------- ### Common Type: SwapStep Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for `SwapStep`, a set of parameters relevant for a specific step within a multi-hop swap. It specifies the pool responsible for the swap and additional step-specific parameters. ```TL-B step#_ pool_addr:MsgAddressInt params:SwapStepParams = SwapStep; ``` ```APIDOC pool_addr: MsgAddressInt (required) - The pool responsible for swapping assets at this step. params: SwapStepParams (required) - Set of extra parameters relevant for a specific step. ``` -------------------------------- ### Pool Event: Swap TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Details the TL-B structure for a "swap" event, used for indexing swap operations in DeDust Protocol. This event provides comprehensive details about the assets involved, amounts, sender, referral, and updated reserves. ```TL-B swap#9c610de3 asset_in:Asset asset_out:Asset amount_in:Coins amount_out:Coins ^[ sender_addr:MsgAddressInt referral_addr:MsgAddress reserve0:Coins reserve1:Coins ] = ExtOutMsgBody; ``` ```APIDOC asset_in: Asset (required) - The asset provided by the user. asset_out: Asset (required) - The asset received by the user. amount_out: Coins (required) - Amount of asset_out received by the user. amount_in: Coins (required) - Amount of asset_in supplied by the user. sender_addr: MsgAddressInt (required) - Address of the contract that initiated the swap. referral_addr: MsgAddress (optional) - Referral address. Required for the Referral Program. reserve0: Coins (required) - Amount of asset0 remaining in reserve after the swap. reserve1: Coins (required) - Amount of asset1 remaining in reserve after the swap. ``` -------------------------------- ### Jetton Vault Message: Swap TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Describes the TL-B structure for a "swap" message specifically for Jetton Vaults. This message is used to initiate token swaps within the vault context, requiring swap parameters. ```TL-B swap#e3a0d482 _:SwapStep swap_params:^SwapParams = ForwardPayload; ``` ```APIDOC swap_params: ^SwapParams (required) ``` -------------------------------- ### Common Type: SwapParams Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for `SwapParams`, a set of parameters relevant for an entire swap operation. It includes optional fields for deadline, recipient address, referral address, and custom payloads for successful or rejected swaps. ```TL-B swap_params#_ deadline:Timestamp recipient_addr:MsgAddressInt referral_addr:MsgAddress fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = SwapParams; ``` ```APIDOC deadline: Timestamp (optional) - Specifies a deadline for the swap. Default: 0 (disabled). recipient_addr: MsgAddress (optional) - Specifies an address where funds will be sent after the swap. Default: sender's address. referral_addr: MsgAddress (optional) - Referral address. Required for the Referral Program. fulfill_payload: Maybe ^Cell (optional) - Custom payload attached to fund transfer upon successful swap. reject_payload: Maybe ^Cell (optional) - Custom payload attached to fund transfer upon rejected swap. ``` -------------------------------- ### Find User's Jetton Wallet for SCALE Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Retrieves the user's jetton wallet address for SCALE tokens. This address is required to transfer jettons to the vault as part of the jetton swapping process. ```TypeScript import { JettonRoot, JettonWallet } from '@dedust/sdk'; // ... const scaleRoot = tonClient.open(JettonRoot.createFromAddress(SCALE_ADDRESS)); const scaleWallet = tonClient.open(await scaleRoot.getWallet(sender.address); ``` -------------------------------- ### Jetton Vault Message: Deposit Liquidity TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Outlines the TL-B structure for depositing liquidity into Jetton Vaults. It specifies required pool parameters and target asset balances, along with optional minimum LP amount and payloads for fulfillment or rejection. ```TL-B deposit_liquidity#40e108d6 pool_params:PoolParams min_lp_amount:Coins asset0_target_balance:Coins asset1_target_balance:Coins fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = ForwardPayload; ``` ```APIDOC pool_params: PoolParams (required) min_lp_amount: Coins (optional) asset0_target_balance: Coins (required) asset1_target_balance: Coins (required) fulfill_payload: Maybe ^Cell (optional) reject_payload: Maybe ^Cell (optional) ``` -------------------------------- ### Pool Message: Swap TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B structure for a "swap" message used in DeDust Protocol pools. This message facilitates token swaps, requiring a TON amount and swap parameters, with an optional query ID. ```TL-B swap#ea06185d query_id:uint64 amount:Coins _:SwapStep swap_params:^SwapParams = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID amount: Coins (required) - TON amount for the swap swap_params: ^SwapParams (required) - Set of parameters relevant for the entire swap ``` -------------------------------- ### Pool API: is_stable Source: https://docs.dedust.io/reference/getting-available-pools/reference/pool Checks whether the pool is configured as a stable-swap pool. Stable-swap pools are designed for assets with pegged values, offering lower slippage. ```APIDOC is_stable(): Inputs: None Returns: is_stable: int (boolean) ``` -------------------------------- ### Factory Message: Create Vault Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for the `create_vault` message used to initiate the creation of a new Vault for a specified asset within the DeDust protocol. It includes a query ID and the asset for which the vault will be created. ```TL-B create_vault#21cfe02b query_id:uint64 asset:Asset = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID asset: Asset (required) - The asset for which a Vault will be created. ``` -------------------------------- ### Common Type: Asset Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for the `Asset` type, which represents different types of assets supported by the DeDust protocol, including native TON coins, Jettons, and extra currencies. ```TL-B native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; extra_currency$0010 currency_id:int32 = Asset; ``` -------------------------------- ### DeDust Liquidity Deposit Contract Lifecycle Source: https://docs.dedust.io/reference/getting-available-pools/docs/concepts Describes the Liquidity Deposit as a short-lived contract responsible for managing user liquidity deposits into a pool, from deployment upon asset acceptance to destruction after the pool's decision. ```APIDOC Liquidity Deposit: Description: A short-lived contract responsible for a user depositing liquidity into a pool. Lifecycle: - Deployed: When one of the assets is accepted. - Destroyed: After the pool either accepts or rejects the liquidity. ``` -------------------------------- ### Pool Event: Deposit TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Describes the TL-B structure for a "deposit" event, used for indexing liquidity deposit operations. This event captures details such as the sender, amounts of assets deposited, updated reserves, and the amount of LP tokens issued. ```TL-B deposit#b544f4a4 sender_addr:MsgAddressInt amount0:Coins amount1:Coins reserve0:Coins reserve1:Coins liquidity:Coins = ExtOutMsgBody; ``` ```APIDOC sender_addr: MsgAddressInt (required) - Address of the contract that initiated the deposit. amount0: Coins (required) - Amount of asset0 provided by the sender. amount1: Coins (required) - Amount of asset1 provided by the sender. reserve0: Coins (required) - Amount of asset0 remaining in reserve after the withdrawal. reserve1: Coins (required) - Amount of asset1 remaining in reserve after the withdrawal. liquidity: Coins (required) - Amount of LP tokens issued for the sender. ``` -------------------------------- ### DeDust Common Type: SwapStep (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for 'SwapStep', a set of parameters relevant for a specific step within a multi-hop swap. It specifies the pool responsible for the swap and additional step-specific parameters. ```APIDOC Type "SwapStep": TL-B: step#_ pool_addr:MsgAddressInt params:SwapStepParams = SwapStep; Parameters: pool_addr: Type: MsgAddressInt Required: yes Description: The pool is responsible for swapping assets at ``` -------------------------------- ### Pool API: get_trade_fee Source: https://docs.dedust.io/reference/getting-available-pools/reference/pool Retrieves the trading fee details applied to swaps within the pool. The fee is represented as a numerator and denominator. ```APIDOC get_trade_fee(): Inputs: None Returns: trade_fee_numerator: int trade_fee_denominator: int ``` -------------------------------- ### TL-B Schema for DeDust Asset Abstraction Source: https://docs.dedust.io/reference/getting-available-pools/docs/concepts Defines the structure of the Asset concept in DeDust, abstracting over different asset types like native coins and jettons. It includes current and upcoming asset type definitions. ```TL-B native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; // Upcoming extra_currency$0010 currency_id:int32 = Asset; ``` -------------------------------- ### DeDust Factory Contract Functionality Source: https://docs.dedust.io/reference/getting-available-pools/docs/concepts Details the Factory contract's role in creating other contracts (pools, vaults) and facilitating the location of specific contracts within the DeDust ecosystem. ```APIDOC Factory: Description: A straightforward contract tasked with creating other contracts (e.g., various types of pools or vaults). Functionality: - Contract creation (pools, vaults). - Location of specific contracts. ``` -------------------------------- ### DeDust.io Event: Withdrawal Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Documents the 'withdrawal' event, detailing the parameters included when liquidity is withdrawn from a DeDust.io pool. It specifies the sender's address, amounts of LP tokens burned, assets received, and remaining reserves. ```TL-B withdrawal#3aa870a6 sender_addr:MsgAddressInt liquidity:Coins amount0:Coins amount1:Coins reserve0:Coins reserve1:Coins = ExtOutMsgBody; ``` ```APIDOC Event withdrawal: sender_addr: MsgAddressInt (Required: yes) - Address of the contract that initiated the withdrawal. liquidity: Coins (Required: yes) - Amount of LP tokens burned by the sender. amount0: Coins (Required: yes) - Amount of `asset0` sent to the sender. amount1: Coins (Required: yes) - Amount of `asset1` sent to the sender. reserve0: Coins (Required: yes) - Amount of `asset0` remaining in reserve after the withdrawal. reserve1: Coins (Required: yes) - Amount of `asset1` remaining in reserve after the withdrawal. ``` -------------------------------- ### Pool Message: Deposit Liquidity TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Specifies the TL-B structure for depositing liquidity into DeDust Protocol pools. It requires the amount, pool parameters, and target balances for assets, with optional minimum LP amount and fulfill/reject payloads. ```TL-B deposit_liquidity#d55e4686 query_id:uint64 amount:Coins pool_params:PoolParams min_lp_amount:Coins asset0_target_balance:Coins asset1_target_balance:Coins fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID amount: Coins (required) pool_params: PoolParams (required) min_lp_amount: Coins (optional) asset0_target_balance: Coins (required) asset1_target_balance: Coins (required) fulfill_payload: Maybe ^Cell (optional) reject_payload: Maybe ^Cell (optional) ``` -------------------------------- ### Check TON Vault and TON-SCALE Pool Deployment Status Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Verifies if both the TON Vault and the TON-SCALE Pool contracts are deployed and in a 'READY' state. This critical step prevents potential fund loss by ensuring transactions are sent only to active contracts. ```TypeScript import { ReadinessStatus } from '@dedust/sdk'; // ... // Check if pool exists: if ((await pool.getReadinessStatus()) !== ReadinessStatus.READY) { throw new Error('Pool (TON, SCALE) does not exist.'); } // Check if vault exits: if ((await tonVault.getReadinessStatus()) !== ReadinessStatus.READY) { throw new Error('Vault (TON) does not exist.'); } ``` -------------------------------- ### Pool Event: Deposit Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'deposit' event structure, an external message (ExtOutMsgBody) used for indexing pool deposit activities. It records the sender, amounts of deposited assets, updated reserves, and issued liquidity tokens. ```TL-B deposit#b544f4a4 sender_addr:MsgAddressInt amount0:Coins amount1:Coins reserve0:Coins reserve1:Coins liquidity:Coins = ExtOutMsgBody; Parameters: sender_addr: MsgAddressInt (Required: yes) - Address of the contract that initiated the deposit. amount0: Coins (Required: yes) - Amount of `asset0` provided by the sender. amount1: Coins (Required: yes) - Amount of `asset1` provided by the sender. reserve0: Coins (Required: yes) - Amount of `asset0` remaining in reserve after the withdrawal. reserve1: Coins (Required: yes) - Amount of `asset1` remaining in reserve after the withdrawal. liquidity: Coins (Required: yes) - Amount of LP tokens issued for the sender. ``` -------------------------------- ### Common Type: PoolParams Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for `PoolParams`, which specifies the type of pool and the two assets involved in it. ```TL-B pool_params#_ pool_type:PoolType asset0:Asset asset1:Asset = PoolParams; ``` ```APIDOC pool_type: PoolType (required) asset0: Asset (required) asset1: Asset (required) ``` -------------------------------- ### Pool API: get_reserves Source: https://docs.dedust.io/reference/getting-available-pools/reference/pool Returns the current reserves of the assets held in the pool. This indicates the quantity of each asset available in the liquidity pool. ```APIDOC get_reserves(): Inputs: None Returns: reserve0: int - reserve of asset0 reserve1: int - reserve of asset1 ``` -------------------------------- ### DeDust Factory Contract Addresses Source: https://docs.dedust.io/reference/getting-available-pools/reference/factory This section provides the mainnet address for the DeDust Factory smart contract, which is essential for interacting with the protocol. ```APIDOC Network Addresses: TON (mainnet): EQBfBWT7X2BHg9tXAxzhz2aKiNTU1tpt5NsiK0uSDW_YAJ67 Explorer: https://tonscan.org/address/EQBfBWT7X2BHg9tXAxzhz2aKiNTU1tpt5NsiK0uSDW_YAJ67 ``` -------------------------------- ### Jetton Vault Message: Deposit Liquidity Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'deposit_liquidity' message structure for Jetton Vaults. This message is part of the ForwardPayload and specifies pool parameters, minimum LP amount, target balances, and optional payloads. ```TL-B deposit_liquidity#40e108d6 pool_params:PoolParams min_lp_amount:Coins asset0_target_balance:Coins asset1_target_balance:Coins fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = ForwardPayload; Parameters: pool_params: PoolParams (Required: yes) - min_lp_amount: Coins (Required: no) - asset0_target_balance: Coins (Required: yes) - asset1_target_balance: Coins (Required: yes) - fulfill_payload: Maybe ^Cell (Required: no) - reject_payload: Maybe ^Cell (Required: no) - ``` -------------------------------- ### Execute Multi-Hop Swap (SCALE to BOLT via TON) in TypeScript Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps This snippet demonstrates how to perform a multi-hop swap by sending a transfer message to the vault. The `forwardPayload` is configured with `VaultJetton.createSwapPayload` to specify the sequence of pools (first SCALE -> TON, then TON -> BOLT) for the chained swap operation. ```TypeScript await scaleWallet.sendTransfer( sender, toNano("0.3"), // 0.3 TON { amount: amountIn, destination: scaleVault.address, responseAddress: USER_ADDR, // return gas to user forwardAmount: toNano("0.25"), forwardPayload: VaultJetton.createSwapPayload({ poolAddress: TON_SCALE.address, // first step: SCALE -> TON limit: minimalAmountOut, next: { poolAddress: TON_BOLT.address, // next step: TON -> BOLT }, }), }, ); ``` -------------------------------- ### DeDust.io Event: Withdrawal TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the structure of the 'withdrawal' event, detailing the parameters emitted when liquidity is successfully withdrawn from a DeDust.io pool. This event provides information about the sender, burned liquidity, received assets, and remaining reserves. ```TL-B withdrawal#3aa870a6 sender_addr:MsgAddressInt liquidity:Coins amount0:Coins amount1:Coins reserve0:Coins reserve1:Coins = ExtOutMsgBody; ``` ```APIDOC Parameters: sender_addr: MsgAddressInt (Required) - Address of the contract that initiated the withdrawal. liquidity: Coins (Required) - Amount of LP tokens burned by the sender. amount0: Coins (Required) - Amount of `asset0` sent to the sender. amount1: Coins (Required) - Amount of `asset1` sent to the sender. reserve0: Coins (Required) - Amount of `asset0` remaining in reserve after the withdrawal. reserve1: Coins (Required) - Amount of `asset1` remaining in reserve after the withdrawal. ``` -------------------------------- ### DeDust Factory Message: Create Vault (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for the 'create_vault' message used to initiate the creation of a new asset vault within the DeDust protocol. It requires an asset to specify which vault will be created. ```APIDOC Message "create_vault": TL-B: create_vault#21cfe02b query_id:uint64 asset:Asset = InMsgBody; Parameters: query_id: Type: uint64 Required: no Description: Query ID asset: Type: Asset (reference: /reference/tlb-schemes#asset) Required: yes Description: The asset for which a Vault will be created. ``` -------------------------------- ### Pool API: get_assets Source: https://docs.dedust.io/reference/getting-available-pools/reference/pool Returns the assets of which the pool consists. This method provides details on the two primary assets held within the liquidity pool. ```APIDOC get_assets(): Inputs: None Returns: asset0: slice (Asset) asset1: slice (Asset) ``` -------------------------------- ### DeDust Common Type: SwapParams (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for 'SwapParams', a set of parameters relevant for an entire swap transaction. It includes options for deadlines, recipient addresses, referral addresses, and custom payloads for successful or rejected swaps. ```APIDOC Type "SwapParams": TL-B: swap_params#_ deadline:Timestamp recipient_addr:MsgAddressInt referral_addr:MsgAddress fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = SwapParams; Parameters: deadline: Type: Timestamp (reference: /reference/tlb-schemes#timestamp) Required: no Description: Specifies a deadline for the swap. If the swap reaches the Pool after this time, it will be rejected. Default: 0 (disabled). recipient_addr: Type: MsgAddress Required: no Description: Specifies an address where funds will be sent after the swap. Default: sender's address. referral_addr: Type: MsgAddress Required: no Description: Referral address. Required for the Referral Program. fulfill_payload: Type: Maybe ^Cell Required: no Description: Custom payload that will be attached to the fund transfer upon a successful swap. reject_payload: Type: Maybe ^Cell Required: no Description: Custom payload that will be attached to the fund transfer upon a rejected swap. ``` -------------------------------- ### Send Swap Message to TON Vault Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Executes the swap by sending a message with the specified amount of TON to the TON Vault. This message targets the identified TON-SCALE pool to complete the asset exchange. ```TypeScript import { toNano } from '@ton/core'; // ... const amountIn = toNano('5'); // 5 TON await tonVault.sendSwap(sender, { poolAddress: pool.address, amount: amountIn, gasAmount: toNano("0.25") }); ``` -------------------------------- ### Find the TON-SCALE Pool Source: https://docs.dedust.io/reference/getting-available-pools/docs/swaps Identifies the address of the volatile pool specifically for TON and SCALE assets. This pool address is crucial for correctly constructing the swap message body. ```TypeScript import { Asset, PoolType } from '@dedust/sdk'; import { Address } from '@ton/core'; const SCALE_ADDRESS = Address.parse('EQBlqsm144Dq6SjbPI4jjZvA1hqTIP3CvHovbIfW_t-SCALE'); const TON = Asset.native(); const SCALE = Asset.jetton(SCALE_ADDRESS); const pool = tonClient.open(await factory.getPool(PoolType.VOLATILE, [TON, SCALE])); ``` -------------------------------- ### Common Type: SwapKind Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for the `SwapKind` type, specifying the direction of a swap. Currently, only `given_in` (input amount specified) is implemented. ```TL-B given_in$0 = SwapKind; given_out$1 = SwapKind; // Not implemented. ``` -------------------------------- ### DeDust Factory Message: Create Volatile Pool (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for the 'create_volatile_pool' message, used to create a new volatile liquidity pool. It requires two assets to define the trading pair. Assets can be reordered without affecting the pool address. ```APIDOC Message "create_volatile_pool": TL-B: create_volatile_pool#97d51f2f query_id:uint64 asset0:Asset asset1:Asset = InMsgBody; Parameters: query_id: Type: uint64 Required: no Description: Query ID asset0: Type: Asset (reference: /reference/tlb-schemes#asset) Required: yes Description: The asset for which a Pool will be created. asset1: Type: Asset (reference: /reference/tlb-schemes#asset) Required: yes Description: The asset for which a Poo will be created. Note: Assets can be reordered (asset0 becomes asset1 and vice versa) to ensure a consistent Pool address regardless of asset order (e.g. A / B or B / A). ``` -------------------------------- ### Configure Swap Recipient Address in DeDust SDK (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/building-advanced-mechanics This snippet demonstrates how to specify a custom recipient address for the coins returned after a swap. By setting `swapParams.recipientAddress` in the DeDust SDK, or `recipient_addr` manually, you can direct swap outcomes to a different user or smart-contract instead of the sender. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, }, }); ``` -------------------------------- ### Attach Custom Payload for Rejected Swaps in DeDust SDK (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/building-advanced-mechanics This snippet illustrates how to attach a custom payload (`rejectPayload`) that is sent if a swap fails or is rejected, for instance, due to excessive slippage or expiration. This allows for specific handling or notifications even when a swap does not complete successfully. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, rejectPayload: CUSTOM_PAYLOAD, }, }); ``` -------------------------------- ### Factory Message: Create Volatile Pool Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for the `create_volatile_pool` message, used to create a new volatile liquidity pool between two specified assets. Assets can be reordered without affecting the pool address. ```TL-B create_volatile_pool#97d51f2f query_id:uint64 asset0:Asset asset1:Asset = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID asset0: Asset (required) - The asset for which a Pool will be created. asset1: Asset (required) - The asset for which a Pool will be created. Note: Assets can be reordered (asset0 becomes asset1 and vice versa) to ensure a consistent address for a Pool regardless of asset order. ``` -------------------------------- ### DeDust Common Type: Asset (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for the 'Asset' type, representing different types of assets supported by the DeDust protocol. It includes native TON coins, Jettons (fungible tokens), and extra currencies. ```APIDOC Type "Asset": TL-B: native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; extra_currency$0010 currency_id:int32 = Asset; ``` -------------------------------- ### DeDust Pool Message: Deposit Liquidity Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'deposit_liquidity' message structure for general DeDust pools. This message is used to add liquidity to a pool, specifying the amounts of assets, target balances, and optional fulfill/reject payloads. ```TL-B deposit_liquidity#d55e4686 query_id:uint64 amount:Coins pool_params:PoolParams min_lp_amount:Coins asset0_target_balance:Coins asset1_target_balance:Coins fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = InMsgBody; Parameters: query_id: uint64 (Required: no) - Query ID amount: Coins (Required: yes) - pool_params: PoolParams (Required: yes) - min_lp_amount: Coins (Required: no) - asset0_target_balance: Coins (Required: yes) - asset1_target_balance: Coins (Required: yes) - fulfill_payload: Maybe ^Cell (Required: no) - reject_payload: Maybe ^Cell (Required: no) - ``` -------------------------------- ### DeDust.io Message: Cancel Deposit TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the structure of the 'cancel_deposit' message, used to initiate the cancellation of a pending liquidity deposit operation within the DeDust.io protocol. It includes a query ID and an optional custom payload. ```TL-B cancel_deposit#166cedee query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC Parameters: query_id: uint64 (Optional) - Query ID payload: Maybe ^Cell (Optional) - Custom payload that will be attached to the funds transfer to the user. ``` -------------------------------- ### Factory get_liquidity_deposit_address Method Source: https://docs.dedust.io/reference/getting-available-pools/reference/factory Calculates the expected address of a Liquidity Deposit contract. This method helps in identifying the specific contract responsible for managing liquidity deposits for a given owner and pool configuration. ```APIDOC Method: get_liquidity_deposit_address Description: Calculates an expected address of Liquidity Deposit contract from a given input. Inputs: owner_addr: slice (Address) pool_type: int (PoolType) asset0: slice (Asset) asset1: slice (Asset) Returns: liquidity_deposit_addr: slice (Address) ``` -------------------------------- ### DeDust Pool Message: Payout Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the 'payout' message structure for general DeDust pools. This message is used to initiate a payout operation, including a query ID and an optional payload. ```TL-B payout#474f86cf query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; Parameters: query_id: uint64 (Required: no) - Query ID payload: Maybe ^Cell (Required: no) - ``` -------------------------------- ### Common Type: PoolType Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for `PoolType`, specifying the type of liquidity pool, such as volatile or stable. ```TL-B volatile$0 = PoolType; stable$1 = PoolType; ``` -------------------------------- ### Cancel pending DeDust liquidity deposit (TypeScript) Source: https://docs.dedust.io/reference/getting-available-pools/docs/liquidity-provisioning This snippet shows how to cancel a pending liquidity deposit that has not yet been fully processed by the DeDust protocol. It retrieves the `LiquidityDeposit` contract instance for the owner, pool type, and assets, then sends a `sendCancelDeposit` transaction. ```TypeScript const liquidityDeposit = tonClient.open( await factory.getLiquidityDeposit({ ownerAddress: sender.address, poolType: PoolType.VOLATILE, assets, }), ); await liquidityDeposit.sendCancelDeposit(sender, {}); ``` -------------------------------- ### Common Type: Timestamp Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference Defines the TL-B scheme for the `Timestamp` type, representing a 32-bit unsigned integer used for time-related parameters like deadlines. ```TL-B timestamp#_ _:uint32 = Timestamp; ``` -------------------------------- ### DeDust Common Type: SwapKind (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for the 'SwapKind' type, specifying the direction or nature of a swap operation. Currently, only the 'given_in' option is implemented, indicating a swap where the input amount is specified. ```APIDOC Type "SwapKind": TL-B: given_in$0 = SwapKind; given_out$1 = SwapKind; // Not implemented. ``` -------------------------------- ### Pool Message: Payout TL-B Definition Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B structure for a "payout" message from DeDust Protocol pools. This message allows for the withdrawal of funds, optionally including a custom payload. ```TL-B payout#474f86cf query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID payload: Maybe ^Cell (optional) ``` -------------------------------- ### DeDust.io Message: Cancel Deposit Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Documents the 'cancel_deposit' message used to cancel a pending liquidity deposit operation. It includes a query ID and an optional custom payload for the funds transfer. ```TL-B cancel_deposit#166cedee query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC Message cancel_deposit: query_id: uint64 (Required: no) - Query ID payload: Maybe ^Cell (Required: no) - Custom payload that will be attached to the funds transfer to the user. ``` -------------------------------- ### Factory get_pool_address Method Source: https://docs.dedust.io/reference/getting-available-pools/reference/factory Calculates the expected address of a Pool contract. This method is used to find the address of a specific liquidity pool based on its type and the two assets it contains. ```APIDOC Method: get_pool_address Description: Calculates an expected address of a Pool contract from a given input. Inputs: pool_type: int (PoolType) asset0: slice (Asset) asset1: slice (Asset) Returns: pool_addr: slice (Address) ``` -------------------------------- ### Factory get_vault_address Method Source: https://docs.dedust.io/reference/getting-available-pools/reference/factory Calculates the expected address of a Vault contract. This method is crucial for determining the location of specific asset vaults within the DeDust protocol. ```APIDOC Method: get_vault_address Description: Calculates an expected address of a Vault contract from a given input. Inputs: asset: slice (Asset) Returns: vault_addr: slice (Address) ``` -------------------------------- ### DeDust Common Type: Timestamp (TL-B) Source: https://docs.dedust.io/reference/getting-available-pools/reference/tlb-schemes Defines the TL-B scheme for the 'Timestamp' type, used to represent a point in time, typically for deadlines or time-sensitive operations within the protocol. ```APIDOC Type "Timestamp": TL-B: timestamp#_ _:uint32 = Timestamp; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.