### Install prerequisite TON libraries Source: https://docs.dedust.io/reference/tlb-schemes/docs/getting-started Install the necessary TON blockchain libraries (@ton/core, @ton/ton, @ton/crypto) required for the DeDust SDK to function. ```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 ``` -------------------------------- ### Install DeDust SDK Source: https://docs.dedust.io/reference/tlb-schemes/docs/getting-started Add the DeDust SDK package (@dedust/sdk) to your project dependencies. ```yarn yarn add @dedust/sdk ``` ```npm npm install --save @dedust/sdk ``` ```pnpm pnpm add @dedust/sdk ``` -------------------------------- ### Initialize DeDust SDK Factory Source: https://docs.dedust.io/reference/tlb-schemes/docs/getting-started Set up the DeDust SDK by importing necessary modules and initializing the Factory contract using a TonClient4 instance, connecting to the TON mainnet. ```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)); ``` -------------------------------- ### Deposit SCALE to Vault for liquidity (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/liquidity-provisioning Transfers the SCALE jetton amount to the jetton Vault contract to complete the liquidity deposit. It involves getting the jetton wallet, sending the transfer, and including a forward payload with pool details. ```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, }), }); ``` -------------------------------- ### API Endpoint: Get Available Pools Source: https://docs.dedust.io/reference/tlb-schemes/reference/getting-available-pools This snippet details the HTTP GET request to retrieve a list of all available liquidity pools from the DeDust API. It specifies the method and the endpoint URL for accessing pool data. ```APIDOC Method: GET Endpoint: https://api.dedust.io/v2/pools ``` -------------------------------- ### DeDust API: Get Pool's Latest Trades Endpoint Source: https://docs.dedust.io/reference/tlb-schemes/reference/getting-pools-latest-trades This API endpoint allows retrieval of the latest trade information for a specified DeDust pool. The `{pool}` placeholder in the URL should be replaced with the unique identifier of the desired pool. ```APIDOC GET https://api.dedust.io/v2/pools/{pool}/trades ``` -------------------------------- ### DeDust SDK: Attach Custom Payload for Fulfilled Swaps Source: https://docs.dedust.io/reference/tlb-schemes/docs/building-advanced-mechanics When a DeDust swap is successfully executed, you can attach a custom payload. This payload will serve as `forward_payload` for jetton transfers or as a general payload for TON payouts. This example shows how to set the `fulfillPayload` property within `swapParams` using the DeDust SDK. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, fulfillPayload: CUSTOM_PAYLOAD, }, }); ``` -------------------------------- ### Prepare input for liquidity deposit (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/liquidity-provisioning Prepares the necessary asset types (TON, SCALE) and their respective amounts for a liquidity deposit operation. It defines the assets as native TON and a specific jetton (SCALE) and sets their target balances. ```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]; ``` -------------------------------- ### Create a Volatile Pool using DeDust SDK Source: https://docs.dedust.io/reference/tlb-schemes/docs/adding-new-jettons This snippet illustrates how to set up a volatile liquidity pool for 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 create it by sending a 'create_volatile_pool' message to the factory contract. ```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], }); } ``` -------------------------------- ### Deposit TON to Vault for liquidity (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/liquidity-provisioning Sends the TON amount to the native TON Vault contract to initiate the liquidity deposit process. It specifies the pool type, assets, target balances, and the amount of TON to deposit. ```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 Pool Contract Methods Source: https://docs.dedust.io/reference/tlb-schemes/docs/adding-new-jettons Documentation for methods available on a DeDust Pool contract instance, primarily for checking its deployment status. ```APIDOC Pool Contract: getReadinessStatus(): Promise Purpose: Checks the deployment status of a pool. Returns: Promise - The readiness status of the pool (e.g., ReadinessStatus.NOT_DEPLOYED). ``` -------------------------------- ### Perform Multi-Hop Jetton Swap (SCALE to BOLT via TON) (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps Shows how to execute a multi-hop swap by sending a transfer message to the Vault. The `forwardPayload` is configured with `VaultJetton.createSwapPayload` to define the sequence of swaps (SCALE -> TON, then TON -> BOLT) using `poolAddress` and `next` properties. ```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 Factory Contract Methods Source: https://docs.dedust.io/reference/tlb-schemes/docs/adding-new-jettons Documentation for key methods of the DeDust Factory contract, which is central to creating new jetton vaults and volatile liquidity pools, and for retrieving pool addresses. ```APIDOC Factory Contract: sendCreateVault(sender: Sender, options: { asset: Asset }) Purpose: Creates a unique vault for a new jetton. Parameters: sender: The sender object for transaction signing. options.asset: The asset (jetton) for which to create the vault. TL-B Message: create_vault sendCreateVolatilePool(sender: Sender, options: { assets: Asset[] }) Purpose: Creates a volatile liquidity pool for a pair of assets. Parameters: sender: The sender object for transaction signing. options.assets: An array containing the two assets for the pool. TL-B Message: create_volatile_pool getPool(poolType: PoolType, assets: Asset[]): Promise
Purpose: Retrieves the address of an existing or potential pool. Parameters: poolType: The type of pool (e.g., PoolType.VOLATILE). assets: An array containing the two assets of the pool. Returns: Promise
- The address of the pool. ``` -------------------------------- ### Find the jetton wallet for the user Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps After identifying the jetton vault, the next step in swapping jettons is to find and open the user's personal jetton wallet for the specific jetton (e.g., SCALE). ```TypeScript import { JettonRoot, JettonWallet } from '@dedust/sdk'; // ... const scaleRoot = tonClient.open(JettonRoot.createFromAddress(SCALE_ADDRESS)); const scaleWallet = tonClient.open(await scaleRoot.getWallet(sender.address); ``` -------------------------------- ### Transfer Jettons to Vault (SCALE) with Swap Payload (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps Demonstrates how to transfer a specified amount of jettons (SCALE) to a Vault address using `sendTransfer`, including a forward payload for a swap operation. It specifies the amount, destination, response address, forward amount, and a swap payload created with `VaultJetton.createSwapPayload`. ```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 }), }); ``` -------------------------------- ### DeDust Pool Contract Get-methods API Documentation Source: https://docs.dedust.io/reference/tlb-schemes/reference/pool Documentation for the read-only methods available on the DeDust Pool contract, allowing retrieval of pool assets, reserves, stability status, trade fees, and swap estimations. ```APIDOC Pool Contract Get-methods: get_assets(): Description: Returns assets of which the pool consists. Inputs: None Returns: asset0: slice (Asset) asset1: slice (Asset) get_reserves(): Description: Returns reserves of the assets in the pool. Inputs: None Returns: reserve0: int - reserve of asset0 reserve1: int - reserve of asset1 is_stable(): Description: Returns whether the pool is based on stable-swap or not. Inputs: None Returns: is_stable: int (boolean) get_trade_fee(): Description: Returns the trading fee details of the pool. Inputs: None Returns: trade_fee_numerator: int trade_fee_denominator: int estimate_swap_out(asset_in: slice (Asset), amount_in: int): Description: Estimates the expected output from a given input. 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. ``` -------------------------------- ### Find Necessary Pools for Multi-Hop Swaps (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps Illustrates how to define assets (SCALE, TON, BOLT) and retrieve their corresponding volatile pools using the DeDust SDK's factory and client. This is a prerequisite step for performing multi-hop swaps. ```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])); ``` -------------------------------- ### Common Type: SwapStepParams Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for `SwapStepParams`, a set of extra parameters relevant for a specific step in a swap. This 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 Parameters: kind: SwapKind (optional) Description: Note: Only `given_in` option is implemented. limit: Coins (optional) Description: Minimum output of the swap. If the actual value is less than specified, the swap will be rejected. next: Maybe ^SwapStep (optional) Description: Reference to the next step. Can be used for multi-hop swaps. ``` -------------------------------- ### Find the Vault (SCALE) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps When swapping jettons, the first step is to locate the specific Vault for the jetton, in this case, the SCALE jetton vault, using the factory. ```TypeScript const scaleVault = tonClient.open(await factory.getJettonVault(SCALE_ADDRESS)); ``` -------------------------------- ### Jetton Vault Message: swap (ForwardPayload) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Describes the structure for a swap message specifically for the Jetton Vault, used as a forward payload, including swap step and parameters. ```TL-B swap#e3a0d482 _:SwapStep swap_params:^SwapParams = ForwardPayload; ``` ```APIDOC Parameters: - swap_params (^SwapParams, required): ``` -------------------------------- ### TL-B Pool Event: swap (ExtOutMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'swap' event for external outgoing message bodies (ExtOutMsgBody), used for indexing purposes. It captures details of a swap, including assets involved, amounts, sender, referral address, and remaining 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. ``` -------------------------------- ### Define Common Type: SwapStepParams (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for 'SwapStepParams', a set of 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, enabling multi-hop swap functionality. ```TL-B step_params#_ kind:SwapKind limit:Coins next:(Maybe ^SwapStep) = SwapStepParams; ``` ```APIDOC Type: SwapStepParams 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. ``` -------------------------------- ### Create a Jetton Vault using DeDust SDK Source: https://docs.dedust.io/reference/tlb-schemes/docs/adding-new-jettons This snippet demonstrates how to create a new vault for a specific jetton using the DeDust SDK. It requires the address of the new jetton and sends a 'create_vault' message to 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), }); ``` -------------------------------- ### Define Common Type: SwapStep (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for 'SwapStep', representing parameters relevant for a specific step within a multi-hop swap. It specifies the pool responsible for swapping assets at this step and includes additional step-specific parameters. ```TL-B step#_ pool_addr:MsgAddressInt params:SwapStepParams = SwapStep; ``` ```APIDOC Type: SwapStep pool_addr: MsgAddressInt (required) - The pool is responsible for swapping assets at this step. params: SwapStepParams (required) - Set of extra parameters relevant for a specific step. ``` -------------------------------- ### Common Type: SwapStep Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for `SwapStep`, a set of parameters relevant for a specific step within a multi-hop swap. It identifies the pool responsible for the swap and includes step-specific parameters. ```TL-B step#_ pool_addr:MsgAddressInt params:SwapStepParams = SwapStep; ``` ```APIDOC Parameters: pool_addr: MsgAddressInt (required) Description: The pool is responsible for swapping assets at this step. params: SwapStepParams (required) Description: Set of extra parameters relevant for a specific step. ``` -------------------------------- ### Withdraw liquidity by burning LP tokens (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/liquidity-provisioning Withdraws liquidity from a DeDust pool by burning the associated LP tokens. It retrieves the pool's LP wallet and sends a burn transaction for the entire balance of LP tokens. ```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(), }); ``` -------------------------------- ### Send a message to a Vault (TON) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps This is the final step to execute the swap: sending a message with the desired amount of TON to the Vault (TON). The Vault then interacts with the Pool to complete the swap. ```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") }); ``` -------------------------------- ### Pool Event: swap (ExtOutMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Details the structure of an external outbound message body representing a swap event within a pool, capturing 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; ``` ```APIDOC Parameters: - 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: deposit_liquidity (ForwardPayload) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the forward payload structure for depositing liquidity into a Jetton Vault, including pool parameters, minimum LP amount, target asset balances, and optional fulfill/reject 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; ``` ```APIDOC Parameters: - 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): ``` -------------------------------- ### TL-B Pool Event: deposit (ExtOutMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'deposit' event for external outgoing message bodies (ExtOutMsgBody), used for indexing purposes. It records details of a liquidity deposit, including sender, amounts of assets, remaining reserves, and issued LP tokens. ```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. ``` -------------------------------- ### TL-B Jetton Vault Message: swap (ForwardPayload) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'swap' message for a Jetton Vault's forward payload. This message is used to initiate a swap operation within the Jetton Vault context and includes specific swap parameters. ```TL-B swap#e3a0d482 _:SwapStep swap_params:^SwapParams = ForwardPayload; ``` ```APIDOC swap_params: ^SwapParams (required) ``` -------------------------------- ### TL-B Message: swap (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'swap' message for an incoming transaction body (InMsgBody), used to initiate a swap operation. It includes a query ID, the amount of TON for the swap, and specific swap parameters. ```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 ``` -------------------------------- ### Message: deposit_liquidity (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Specifies the inbound message body structure for depositing liquidity into a pool, including query ID, amount, pool parameters, minimum LP amount, target balances for assets, 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; ``` ```APIDOC Parameters: - 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): ``` -------------------------------- ### Common Type: SwapParams Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for `SwapParams`, a collection of parameters relevant for the entire swap operation, including a deadline, recipient address, referral address, and optional custom payloads for successful or rejected transfers. ```TL-B swap_params#_ deadline:Timestamp recipient_addr:MsgAddressInt referral_addr:MsgAddress fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = SwapParams; ``` ```APIDOC Parameters: deadline: Timestamp (optional) 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: MsgAddress (optional) Description: Specifies an address where funds will be sent after the swap. Default: sender's address. referral_addr: MsgAddress (optional) Description: Referral address. Required for the Referral Program. fulfill_payload: Maybe ^Cell (optional) Description: Custom payload that will be attached to the fund transfer upon a successful swap. reject_payload: Maybe ^Cell (optional) Description: Custom payload that will be attached to the fund transfer upon a rejected swap. ``` -------------------------------- ### Pool Event: deposit (ExtOutMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Describes the external outbound message body for a deposit event, including sender address, amounts of assets provided, 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 Parameters: - 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. ``` -------------------------------- ### Find the Pool (TON, SCALE) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps To correctly construct the swap message, it's necessary to identify the address of the specific Pool (TON, SCALE) where the assets will be swapped. This code snippet shows how to obtain the pool address using the factory. ```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])); ``` -------------------------------- ### Factory Message: create_vault Source: https://docs.dedust.io/reference/tlb-schemes/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 for transaction tracking and the definition of the asset. ```TL-B create_vault#21cfe02b query_id:uint64 asset:Asset = InMsgBody; ``` ```APIDOC Parameters: query_id: uint64 (optional) Description: Query ID asset: Asset (required) Description: The asset for which a Vault will be created. ``` -------------------------------- ### Common Type: PoolParams Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for `PoolParams`, which specifies the configuration parameters for a liquidity pool, including its type and the two assets it manages. ```TL-B pool_params#_ pool_type:PoolType asset0:Asset asset1:Asset = PoolParams; ``` ```APIDOC Parameters: pool_type: PoolType (required) Description: asset0: Asset (required) Description: asset1: Asset (required) Description: ``` -------------------------------- ### Define Common Type: SwapParams (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for 'SwapParams', a set of parameters relevant for an entire swap operation. It includes optional fields for a deadline, recipient address, referral address, and custom payloads for successful or rejected transfers. ```TL-B swap_params#_ deadline:Timestamp recipient_addr:MsgAddressInt referral_addr:MsgAddress fulfill_payload:(Maybe ^Cell) reject_payload:(Maybe ^Cell) = SwapParams; ``` ```APIDOC Type: SwapParams deadline: Timestamp (optional) - Specifies a deadline for the swap. If the swap reaches the Pool after this time, it will be rejected. 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 that will be attached to the fund transfer upon a successful swap. reject_payload: Maybe ^Cell (optional) - Custom payload that will be attached to the fund transfer upon a rejected swap. ``` -------------------------------- ### TL-B Schema for DeDust Asset Source: https://docs.dedust.io/reference/tlb-schemes/docs/concepts This TL-B schema defines the 'Asset' concept in DeDust, serving as an abstraction over different asset types. It includes definitions for native coins, jettons, and an upcoming extra-currency type, simplifying swap processes and enabling easy integration of new asset types. ```TL-B native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; // Upcoming extra_currency$0010 currency_id:int32 = Asset; ``` -------------------------------- ### TL-B Message: deposit_liquidity (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'deposit_liquidity' message for an incoming transaction body (InMsgBody), used to deposit liquidity into a pool. It specifies the amount, pool parameters, minimum LP amount, target balances for assets, 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; ``` ```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) ``` -------------------------------- ### TL-B Jetton Vault Message: deposit_liquidity (ForwardPayload) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'deposit_liquidity' message for a Jetton Vault's forward payload. This message is used to deposit liquidity into a Jetton Vault pool, specifying pool parameters, minimum LP amount, target balances for assets, and optional fulfill/reject 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; ``` ```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) ``` -------------------------------- ### Factory Message: create_volatile_pool Source: https://docs.dedust.io/reference/tlb-schemes/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's consistent address. ```TL-B create_volatile_pool#97d51f2f query_id:uint64 asset0:Asset asset1:Asset = InMsgBody; ``` ```APIDOC Parameters: query_id: uint64 (optional) Description: Query ID asset0: Asset (required) Description: The asset for which a Pool will be created. asset1: Asset (required) Description: The asset for which a Pool will be created. Note: Assets can be reordered (asset0 becomes asset1 and vice versa). This ensures a consistent address for a Pool regardless of asset order (e.g. A / B or B / A). ``` -------------------------------- ### Common Type: SwapKind Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for the `SwapKind` type, indicating the direction or nature of a swap. Currently, only the `given_in` option is implemented. ```TL-B given_in$0 = SwapKind; given_out$1 = SwapKind; // Not implemented. ``` -------------------------------- ### Find the Vault (TON) Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps The Factory is useful for locating any contract within the DeDust Protocol. This snippet demonstrates how to locate and open the Vault (TON) contract, which will be used to send the swap message. ```TypeScript import { Asset, VaultNative } from '@dedust/sdk'; // ... // NOTE: We will use tonVault to send a message. const tonVault = tonClient.open(await factory.getNativeVault()); ``` -------------------------------- ### Common Type: Asset Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for the `Asset` type, representing different categories of assets supported by the DeDust protocol, including native TON, Jettons, and extra currencies. ```TL-B native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; extra_currency$0010 currency_id:int32 = Asset; ``` -------------------------------- ### TL-B Event: Withdrawal Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the structure of a 'withdrawal' event in TL-B, detailing the sender's address, liquidity burned, amounts of assets withdrawn (amount0, amount1), and remaining reserves (reserve0, reserve1) after the operation. This event is an ExtOutMsgBody. ```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. ``` -------------------------------- ### Define Factory Message: Create Vault (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for the 'create_vault' message, an inbound message body used by the DeDust factory. This message initiates the creation of a new vault for a specified asset, identified by a query ID. ```TL-B create_vault#21cfe02b query_id:uint64 asset:Asset = InMsgBody; ``` ```APIDOC Message: create_vault query_id: uint64 (optional) - Query ID asset: Asset (required) - The asset for which a Vault will be created. ``` -------------------------------- ### Cancel a pending liquidity deposit (TypeScript) Source: https://docs.dedust.io/reference/tlb-schemes/docs/liquidity-provisioning Cancels a previously initiated, but not yet completed, liquidity deposit. It retrieves the specific liquidity deposit contract based on owner, pool type, and assets, then sends a cancel deposit transaction. ```TypeScript const liquidityDeposit = tonClient.open( await factory.getLiquidityDeposit({ ownerAddress: sender.address, poolType: PoolType.VOLATILE, assets, }), ); await liquidityDeposit.sendCancelDeposit(sender, {}); ``` -------------------------------- ### Message: swap (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the structure for a swap message as an inbound message body within the DeDust protocol, specifying the query ID, swap amount, and additional swap parameters. ```TL-B swap#ea06185d query_id:uint64 amount:Coins _:SwapStep swap_params:^SwapParams = InMsgBody; ``` ```APIDOC Parameters: - 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 ``` -------------------------------- ### TL-B Event: withdrawal Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the structure for a 'withdrawal' event in Dedust.io, indicating the successful withdrawal of assets from a liquidity pool. It includes details about the sender, the amount of LP tokens burned, the amounts of asset0 and asset1 received, and the remaining reserves in the pool. ```TL-B withdrawal#3aa870a6 sender_addr:MsgAddressInt liquidity:Coins amount0:Coins amount1:Coins reserve0:Coins reserve1:Coins = ExtOutMsgBody; ``` ```APIDOC 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. ``` -------------------------------- ### Check if Vault (TON) and Pool (TON, SCALE) are deployed Source: https://docs.dedust.io/reference/tlb-schemes/docs/swaps Before sending funds, it is crucial to verify that both the Pool and Vault contracts are deployed and ready. Sending funds to an inactive contract can result in irretrievable loss. ```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.'); } ``` -------------------------------- ### DeDust Factory Contract Addresses Source: https://docs.dedust.io/reference/tlb-schemes/reference/factory Provides the mainnet address for the DeDust Factory smart contract, which is essential for interacting with the protocol on the TON blockchain. ```APIDOC Network: TON (mainnet) Address: EQBfBWT7X2BHg9tXAxzhz2aKiNTU1tpt5NsiK0uSDW_YAJ67 ``` -------------------------------- ### Message: payout (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the inbound message body for a payout operation, including a query ID and an optional payload. ```TL-B payout#474f86cf query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC Parameters: - query_id (uint64, optional): Query ID - payload (Maybe ^Cell, optional): ``` -------------------------------- ### Define Common Type: PoolParams (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for 'PoolParams', a set of parameters describing a liquidity pool. It includes the pool's type and the two assets involved in the liquidity pair. ```TL-B pool_params#_ pool_type:PoolType asset0:Asset asset1:Asset = PoolParams; ``` ```APIDOC Type: PoolParams pool_type: PoolType (required) asset0: Asset (required) asset1: Asset (required) ``` -------------------------------- ### DeDust SDK: Attach Custom Payload for Rejected Swaps Source: https://docs.dedust.io/reference/tlb-schemes/docs/building-advanced-mechanics In cases where a DeDust swap is rejected due to reasons like excessive slippage or expiration, funds are typically returned to the sender. This snippet illustrates how to attach a custom payload for such rejected swaps by setting the `rejectPayload` property within `swapParams` using the DeDust SDK, allowing for specific handling of failed transactions. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, rejectPayload: CUSTOM_PAYLOAD, }, }); ``` -------------------------------- ### Factory Get-method: Calculate Pool Address Source: https://docs.dedust.io/reference/tlb-schemes/reference/factory Describes the `get_pool_address` method of the DeDust Factory contract. This method calculates the expected address of a Pool contract given its type and two asset inputs. ```APIDOC get_pool_address Inputs: pool_type: int (PoolType) asset0: slice (Asset) asset1: slice (Asset) Returns: pool_addr: slice (Address) ``` -------------------------------- ### Factory Get-method: Calculate Liquidity Deposit Address Source: https://docs.dedust.io/reference/tlb-schemes/reference/factory Describes the `get_liquidity_deposit_address` method of the DeDust Factory contract. This method calculates the expected address of a Liquidity Deposit contract based on the owner's address, pool type, and two asset inputs. ```APIDOC get_liquidity_deposit_address Inputs: owner_addr: slice (Address) pool_type: int (PoolType) asset0: slice (Asset) asset1: slice (Asset) Returns: liquidity_deposit_addr: slice (Address) ``` -------------------------------- ### Define Factory Message: Create Volatile Pool (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for the 'create_volatile_pool' message, an inbound message body used by the DeDust factory. This message initiates the creation of 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 Message: create_volatile_pool 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. ``` -------------------------------- ### Common Type: PoolType Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for `PoolType`, specifying the classification of a liquidity pool, such as volatile or stable. ```TL-B volatile$0 = PoolType; stable$1 = PoolType; ``` -------------------------------- ### TL-B Message: payout (InMsgBody) Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the 'payout' message for an incoming transaction body (InMsgBody), used to initiate a payout. It includes a query ID and an optional payload. ```TL-B payout#474f86cf query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC query_id: uint64 (optional) - Query ID payload: Maybe ^Cell (optional) ``` -------------------------------- ### Factory Get-method: Calculate Vault Address Source: https://docs.dedust.io/reference/tlb-schemes/reference/factory Describes the `get_vault_address` method of the DeDust Factory contract. This method calculates the expected address of a Vault contract based on a given asset input. ```APIDOC get_vault_address Inputs: asset: slice (Asset) Returns: vault_addr: slice (Address) ``` -------------------------------- ### Common Type: Timestamp Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the TL-B scheme for the `Timestamp` type, which is represented as a 32-bit unsigned integer. ```TL-B timestamp#_ _:uint32 = Timestamp; ``` -------------------------------- ### Define Common Type: SwapKind (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for the 'SwapKind' common 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. ```TL-B given_in$0 = SwapKind; given_out$1 = SwapKind; // Not implemented. ``` ```APIDOC Type: SwapKind Variants: given_in$0 given_out$1 (Not implemented) ``` -------------------------------- ### TL-B Message: Cancel Deposit Source: https://docs.dedust.io/reference/tlb-schemes/reference Defines the structure of a 'cancel_deposit' message in TL-B, used to cancel a liquidity deposit. It includes a query ID and an optional custom payload. This message is an InMsgBody. ```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. ``` -------------------------------- ### Define Common Type: Asset (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for the 'Asset' common type, representing different types of assets within the DeDust protocol. It can be a native currency, a jetton (fungible token), or an extra currency, each with specific identifying parameters. ```TL-B native$0000 = Asset; jetton$0001 workchain_id:int8 address:uint256 = Asset; extra_currency$0010 currency_id:int32 = Asset; ``` ```APIDOC Type: Asset Variants: native$0000 jetton$0001 workchain_id: int8 address: uint256 extra_currency$0010 currency_id: int32 ``` -------------------------------- ### Define Common Type: PoolType (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for 'PoolType', specifying the type of a liquidity pool. This enumeration distinguishes between different pool mechanisms, such as volatile and stable pools. ```TL-B volatile$0 = PoolType; stable$1 = PoolType; ``` ```APIDOC Type: PoolType Variants: volatile$0 stable$1 ``` -------------------------------- ### TL-B Message: cancel_deposit Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Specifies the 'cancel_deposit' message structure used to cancel a pending liquidity deposit operation. It includes a query identifier and an optional custom payload for the user's funds transfer. ```TL-B cancel_deposit#166cedee query_id:uint64 payload:(Maybe ^Cell) = InMsgBody; ``` ```APIDOC query_id: uint64 (Optional) - Query ID payload: Maybe ^Cell (Optional) - Custom payload that will be attached to the funds transfer to the user. ``` -------------------------------- ### Define Common Type: Timestamp (TL-B) Source: https://docs.dedust.io/reference/tlb-schemes/reference/tlb-schemes Defines the TL-B scheme for the 'Timestamp' common type, used to represent a point in time. This type is typically used for specifying deadlines in protocol messages. ```TL-B timestamp#_ _:uint32 = Timestamp; ``` ```APIDOC Type: Timestamp _: uint32 ``` -------------------------------- ### DeDust SDK: Configure Swap Recipient Address Source: https://docs.dedust.io/reference/tlb-schemes/docs/building-advanced-mechanics By default, DeDust swaps return coins to the sender. This snippet demonstrates how to override this behavior by setting a custom `recipientAddress` within the `swapParams` object when creating a swap payload using the DeDust SDK. This is useful for directing swap returns to another user or a different smart contract. ```TypeScript const forwardPayload = VaultJetton.createSwapPayload({ /* ... */ swapParams: { recipientAddress: RECIPIENT_ADDRESS, }, }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.