### Install TAPP Exchange SDK Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Installs the TAPP Exchange SDK using npm. This is the first step to integrating the SDK into your project. ```bash npm install @tapp-exchange/sdk ``` -------------------------------- ### Installation Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Install the TAPP Exchange TypeScript SDK using npm. ```APIDOC ## Installation Install the TAPP Exchange TypeScript SDK using npm. ```bash npm install @tapp-exchange/sdk ``` ``` -------------------------------- ### Get Campaign Start Time (JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Fetches the start timestamp of a campaign. Inputs include the pool address and campaign index. The `aptos.view` method is used to query the smart contract for this information. ```javascript const startTime = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_start_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` -------------------------------- ### Create Stable Pool Example Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc This example shows how to serialize parameters for creating a Stable pool. It covers pool type, assets, fee, amplification factor, off-peg multiplier, initial amounts for each coin, and the minimum LP mint amount. The amplification factor must be between 100 and 1000. ```typescript // pool type ser.serializeU8(4); // assets, support up to 4 coins. ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]); // fee 1_000_000 for 0.01%, and 5_000_000 for 0.05% ser.serializeU64(fee); // amp. Between 100 to max 1000 ser.serializeU256(amp); // off peg multiplier ser.serializeU256(offpeg_fee_multiplier); // Initial liquidity for each coins ser.serializeVector(amounts.map(amount => new U256(amount))); // minimum LP mint amount ser.serializeU256(min_mint_amount); ``` -------------------------------- ### AMM Swap Example Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc This example demonstrates the serialization process for performing an AMM swap. It includes the pool ID, swap direction (token A to B or vice-versa), whether the input amount is fixed, the input amount, and the minimum expected output amount. This is used for functions like `swap_exact_tokens_for_tokens` or `swap_tokens_for_exact_tokens`. ```typescript // pool id ser.serialize(AccountAddress.fromString(poolId)); // swap from tokenA to tokenB ser.serializeBool(aToB); // fixed_amount_in. // True = swap_exact_tokens_for_tokens // False = swap_tokens_for_exact_tokens ser.serializeBool(fixed_amount_in); // amount in ser.serializeU64(amountIn); // minimum amount out ser.serializeU64(amountOutMin); ``` -------------------------------- ### Get Campaign Start Time Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the start timestamp of a campaign. ```APIDOC ## GET /campaigns/start_time ### Description Retrieves the start timestamp of a campaign. ### Method GET ### Endpoint `/campaigns/start_time` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. - **campaignIndex** (u64) - Required - The index of the campaign. ### Request Example ```javascript const startTime = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_start_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **startTime** (u64) - The start timestamp of the campaign. ``` -------------------------------- ### Get Campaign Start Time (JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the start timestamp (in seconds) for a campaign. This view function takes the pool address and campaign index and returns a u64 representing the start time. ```javascript const startTime = await aptos.view({ function: `${viewAddress}::amm_views::get_campaign_start_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` -------------------------------- ### Get Position Data Example (JSON) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/api This JSON snippet illustrates the structure of the response when querying for position data via the public/position method. It includes detailed APR breakdown, collected fees, creation timestamp, and estimated values for fees, withdrawals, and incentives. ```json { "jsonrpc": "2.0", "id": 3, "method": "public/position", "result": { "data": [ { "apr": { "boostedAprPercentage": "11.8762139379439780526392657412958746681517539133477195240532571877065432914738929279576999339061467300", "campaignAprs": [ { "aprPercentage": "11.8762139379439780526392657412958746681517539133477195240532571877065432914738929279576999339061467300", "campaignIdx": "5", "token": { "addr": "0xabc", "color": "#E4FE54", "decimals": 8, "img": "https://img.svg", "symbol": "kAPT", "verified": true } } ], "feeAprPercentage": "0.162086325719364321429338815505616366863250732421875", "totalAprPercentage": "12.0383002636633428181578144068641072044676718820977195240532571877065432914738929279576999339061467300" }, "collectedFees": "0", "createdAt": "2025-07-31T14:06:24.905776Z", "estimatedCollectFees": [ { "addr": "0xabc", "amount": "100", "color": "#E4FE54", "decimals": 8, "idx": 0, "img": "https://img.svg", "symbol": "kAPT", "usd": "10", "verified": true } ] } ] } } ``` -------------------------------- ### Get Campaign Start Time Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the start timestamp of a campaign. This function requires the pool address and campaign index, returning a u64 representing the start time. ```javascript const startTime = await aptos.view({ function: `${viewAddress}::clmm_views::get_campaign_start_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` -------------------------------- ### Create Concentrated Liquidity Market Maker (CLMM) Pool Example Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc This example demonstrates how to serialize parameters for creating a Concentrated Liquidity Market Maker (CLMM) pool. It includes pool type, assets, fee, initial square root price, amounts, and tick boundaries. Ensure correct types and values are used for each parameter. ```typescript // pool type ser.serializeU8(3); // assets ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]); // fee. 100 for 0.01%, 500 for 0.05%, 3000 for 0.3%, 10000 for 1%. ser.serializeU64(fee); // initial square root price. ser.serializeU128(sqrtPrice); // The desired amount of the first token to be added ser.serializeU64(amountA); // The desired amount of the second token to be added ser.serializeU64(amountB); // fixed_amount_a true if we expect amount_a to be fixed. ser.serializeBool(fixed_amount_a); // lower_tick ser.serializeU64(lower_tick); // upper_tick ser.serializeU64(upper_tick); ``` -------------------------------- ### get_campaign_start_time Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the start timestamp of a campaign. ```APIDOC ## get_campaign_start_time ### Description Returns the start timestamp of a campaign. ### Method VIEW ### Endpoint `/get_campaign_start_time` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - Pool unique identifier. - **campaign_idx** (u64) - Required - Campaign index. ### Request Example ```json { "pool_addr": "0x123", "campaign_idx": 1 } ``` ### Response #### Success Response (200) - **start_time** (u64) - The Unix timestamp when the campaign started. #### Response Example ```json { "start_time": "1678886400" } ``` ``` -------------------------------- ### Stable Pool Liquidity Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Parameters and examples for adding liquidity to a stable pool. ```APIDOC ## POST /add_liquidity/stable ### Description This endpoint allows users to add liquidity to a stable pool on Tapp Exchange. ### Method POST ### Endpoint /add_liquidity/stable ### Parameters #### Request Body - **poolType** (u8) - Required - Pool type (4 = Stable) - **assets** (vector
) - Required - List of coin types (max 4 addresses) - **fee** (u64) - Required - Fee in basis points (bps) - **amp** (u256) - Required - Amplification factor. Value must be between 100 and 1000. - **offPegMultiplier** (u256) - Required - Off peg multiplier. ### Request Example ```json { "poolType": 4, "assets": ["0xcoinA", "0xcoinB"], "fee": 3000, "amp": "1000", "offPegMultiplier": "1000" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "Liquidity added successfully" } ``` ``` -------------------------------- ### Get Positions Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Retrieves a paginated list of liquidity positions for a given user address. ```APIDOC ## Get Positions ### Description Retrieves a paginated list of liquidity positions for a given user address. ### Method GET ### Endpoint `/api/positions` (example endpoint) ### Parameters #### Query Parameters - **userAddr** (string) - Required - The user's wallet address to fetch positions for. - **page** (number) - Optional - The page number for pagination (defaults to 1). - **size** (number) - Optional - The number of results per page (defaults to 10). ### Request Example ``` GET /api/positions?userAddr=0xuser&page=1&size=10 ``` ### Response #### Success Response (200) - **positions** (array) - A list of liquidity positions. - **poolId** (string) - The ID of the pool. - **positionAddr** (string) - The address of the position. - **amountA** (number) - The amount of token A in the position. - **amountB** (number) - The amount of token B in the position. #### Response Example ```json { "positions": [ { "poolId": "0xpool1", "positionAddr": "0xposition1", "amountA": 1000, "amountB": 2000 }, { "poolId": "0xpool2", "positionAddr": "0xposition2", "amountA": 500, "amountB": 1500 } ] } ``` ``` -------------------------------- ### GET /view/stable_views/calc_ratio_amounts Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Calculates the amounts of each coin based on a given liquidity ratio within a stable pool. ```APIDOC ## GET /view/stable_views/calc_ratio_amounts ### Description Calculates the amounts of each coin based on a given liquidity ratio within a stable pool. ### Method GET ### Endpoint `/view/stable_views/calc_ratio_amounts` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **liquidity** (u256) - Required - The liquidity ratio to use for the calculation. ### Request Example ```javascript const amounts = await aptos.view({ function: `${viewAddress}::stable_views::calc_ratio_amounts`, type_arguments: [], arguments: [poolAddress, liquidity], }); ``` ### Response #### Success Response (200) - **amounts** (vector) - A vector containing the calculated amounts of each coin. #### Response Example ```json { "amounts": ["500000000000000000", "500000000000000000"] } ``` ``` -------------------------------- ### Get Campaign Emission Rate with Aptos SDK Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the emission rate per second for a given campaign in a stable swap pool. This function requires the pool address and the campaign index. ```javascript const ratePerSecond = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_rate_per_second`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` -------------------------------- ### Initialization Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Initialize the Tapp TypeScript SDK. Currently supports MAINNET. ```APIDOC ## Initialization The Tapp TypeScript SDK provides a convenient helper function `initTappSDK` to initialize the SDK. ***(Currently only supports MAINNET)*** ```ts import { initTappSDK } from '@tapp-exchange/sdk'; import { Network } from '@aptos-labs/ts-sdk'; const sdk = initTappSDK({ network: Network.MAINNET, // optional. Default: MAINNET url: 'https://....' // optional. }); ``` ``` -------------------------------- ### Initialize TAPP Exchange SDK (TypeScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Initializes the TAPP Exchange TypeScript SDK. Currently supports MAINNET. Requires network configuration and optionally a custom URL. ```typescript import { initTappSDK } from '@tapp-exchange/sdk'; import { Network } from '@aptos-labs/ts-sdk'; const sdk = initTappSDK({ network: Network.MAINNET, // optional. Default: MAINNET url: 'https://....' // optional. }); ``` -------------------------------- ### Get Campaign End Time (JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Fetches the end timestamp (in seconds) for a campaign. Similar to retrieving the start time, this function requires the pool address and campaign index and returns a u64. ```javascript const endTime = await aptos.view({ function: `${viewAddress}::amm_views::get_campaign_end_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` -------------------------------- ### Sign and Submit Swap Transaction (Golang) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/api Provides an example of signing and submitting a transaction using Golang. This involves decoding a hex payload, deserializing it into a raw Aptos transaction, signing it with the sender's credentials, and then submitting the signed transaction to the client. ```golang payloadHex := “this value received from our backend” txBytes, err := hex.DecodeString(payloadHex) if err != nil { // Handle error here } // Convert to raw transaction deserializer := bcs.NewDeserializer(txBytes) rawTxn := &aptos.RawTransaction{} rawTxn.UnmarshalBCS(deserializer) if deserializer.Error() != nil { // handle error here } // Sign and Submit transaction signedTxn, err := rawTxn.SignedTransaction(sender) if err != nil { // handle error here } submittedTxn, err := client.SubmitTransaction(signedTxn) if err != nil { // handle error here} ``` -------------------------------- ### TAPP View API - Get Pool Metas Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves metadata for all TAPP pools. This endpoint is useful for getting a comprehensive overview of available pools. ```APIDOC ## GET /view/get_pool_metas ### Description Returns metadata for all TAPP pools. ### Method GET ### Endpoint /view/get_pool_metas ### Parameters #### Query Parameters * None #### Request Body * None ### Request Example ```json { "function": "::tapp_views::get_pool_metas", "type_arguments": [], "arguments": [] } ``` ### Response #### Success Response (200) - **poolMetas** (vector) - A vector containing metadata for each TAPP pool. #### Response Example ```json [ { "pool_address": "0x123...", "token_x": "0xabc...", "token_y": "0xdef..." }, { "pool_address": "0x456...", "token_x": "0xghi...", "token_y": "0xjkl..." } ] ``` ``` -------------------------------- ### Create Stable Pool and Add Liquidity Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Creates a Stable pool and adds initial liquidity. ```APIDOC ## Create Stable Pool and Add Liquidity ### Description Creates a Stable pool and adds initial liquidity. ### Method POST (assumed, as it creates a pool and adds liquidity) ### Endpoint /pool/stable/create ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **tokenAddress** (string[]) - Required - An array of token addresses. - **fee** (number) - Required - The fee traders will pay to Use your pool's liquidity. - **amounts** (number[]) - Required - The initial token amounts. - **amplificationFactor** (number) - Required - Amplification factor. - **offpeg_fee_multiplier** (number) - Optional - Multiplier applied to fee when assets are off-peg. Defaults to `20_000_000_000`. ### Request Example ```json { "tokenAddress": ["0xtoken1", "0xtoken2", "0xtoken3"], "fee": 500, "amounts": [20000000000, 10000000000, 2000000000], "amplificationFactor": 1000 } ``` ### Response #### Success Response (200) - **poolId** (string) - The address of the newly created Stable pool. - **liquidity** (string) - Identifier for the added liquidity. #### Response Example ```json { "poolId": "0xnew_stable_pool_address", "liquidity": "liquidity_identifier" } ``` ``` -------------------------------- ### Create Stable Pool and Add Liquidity Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Creates a Stable pool and adds initial liquidity. This function requires token addresses, a trading fee, initial amounts, and an amplification factor. It also allows for an optional off-peg fee multiplier. Transaction signing is handled via the wallet hook, and pool creation uses the SDK. ```typescript const { signAndSubmitTransaction, account } = useWallet(); async function createStablePoolAndAddLiquidity() { const params: CreateStablePoolAndAddLiquidityParams = { tokenAddress: ['0xtoken1', '0xtoken2', '0xtoken3'], fee: 500, amounts: [20000000000, 10000000000, 2000000000], amplificationFactor: 1000, } const data = sdk.Position.createStablePoolAndAddLiquidity(params); await signAndSubmitTransaction({ sender: account.address, data: data }); } ``` -------------------------------- ### Preview swap amounts (Stable Pools Math) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/stable-swap Read-only helper function to preview the amount of output tokens ('dx' or 'dy') that would be received for a given input amount during a swap. Useful for user interfaces. ```Solidity function get_dx(uint256 i, uint256 j, uint256 dx, uint256[] memory xp, uint256 amp) internal pure returns (uint256) { // Implementation details for get_dx } function get_dy(uint256 i, uint256 j, uint256 dy, uint256[] memory xp, uint256 amp) internal pure returns (uint256) { // Implementation details for get_dy } ``` -------------------------------- ### Swap API Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk APIs for performing and estimating swaps on TAPP Exchange. ```APIDOC ## Swap ### Estimate Swap Amount Estimates the amount received or needed for a swap, depending on input direction. **Params** * `amount`: `number` The amount for estimation (used as input or desired output depending on `field`). * `poolId`: `string` The identifier of the pool. * `pair`: `[number, number]` A tuple of token indexes to swap, e.g., `[0, 1]` means token at index 0 is being swapped for token at index 1. * `a2b`: `boolean` Swap direction — `true` for token at `pair[0]` to `pair[1]`, `false` for `pair[1]` to `pair[0]`. * `field` (optional): `input | output` Indicates if `amount` is an "input" or "output" amount (defaults to "input"). ```ts const getEstSwap = async () => { const result = await sdk.Swap.getEstSwapAmount({ poolId: "0xpool", a2b: true, field: 'input', // input or output amount: 1000000000, pair: [0, 1] }); if(result.error instanceof TradeSizeExceedsError) { console.error(result.error.message) console.error('max allowed amount', result.error.maxAmountIn); } console.log(result); }; ``` ### Get Swap Route Retrieves the pool route information between two tokens. Use `sdk.Swap.getRoute` method **Example** ```ts async function getRoute() { const token0 = '0xtoken1' const token1 = '0xtoken2' const poolInfo = await sdk.Swap.getRoute(token0, token1); console.log(poolInfo) } ``` ### AMM Swap Creates a swap payload for an AMM pool Use `sdk.Swap.swapAMMTransactionPayload` method **Params:** * `poolId`: `string` The address of the pool in which the swap is performed. * `a2b`: `boolean` Direction of the swap; `true` for token A to B, `false` for B to A. * `fixedAmountIn`: `boolean` Whether the input amount is fixed (defaults to `true`). * `amount0`: `number` Amount of token A. * `amount1`: `number` Amount of token B. ```ts const { signAndSubmitTransaction, account } = useWallet(); async function swapAMM() { const params: SwapAMMParams = { poolId: '0xpool', a2b: true, fixedAmountIn: true, amount0: 100000000, amount1: 10000000, } const data = sdk.Swap.swapAMMTransactionPayload(params); await signAndSubmitTransaction({ sender: account.address, data: data }); } ``` ``` -------------------------------- ### Initialize Serializer - TypeScript Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Initializes a Serializer instance required for preparing transaction data. This is a fundamental step before interacting with Aptos smart contracts for serialization. ```typescript const ser = new Serializer(); ``` -------------------------------- ### Get Campaign End Time Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the end timestamp of a campaign. ```APIDOC ## GET /campaigns/end_time ### Description Retrieves the end timestamp of a campaign. ### Method GET ### Endpoint `/campaigns/end_time` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. - **campaignIndex** (u64) - Required - The index of the campaign. ### Request Example ```javascript const endTime = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_end_time`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **endTime** (u64) - The end timestamp of the campaign. ``` -------------------------------- ### Move Function: create_pool Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/stable-swap Initializes a new stable swap pool. It requires a signer, asset addresses, their decimals, trading fee tier, BCS-encoded additional arguments (like initial A factor), and the creator's address for event emission. Reserves start at zero, and rate multipliers normalize tokens to 36 decimals. ```move create_pool(pool_signer, assets, assets_decimals, fee, rest_args, creator) ``` -------------------------------- ### Create AMM Pool and Add Liquidity Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Creates an Automated Market Maker (AMM) pool and adds initial liquidity. ```APIDOC ## Create AMM Pool and Add Liquidity ### Description Creates an AMM pool and adds initial liquidity. ### Method POST (assumed, as it creates a pool and adds liquidity) ### Endpoint /pool/amm/create ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **tokenAddress** (string[]) - Required - An array of token addresses. - **fee** (number) - Required - The fee traders will pay to use your pool's liquidity. - **amounts** (number[]) - Required - The initial token amounts. ### Request Example ```json { "tokenAddress": ["0xtoken1", "0xtoken2"], "fee": 3000, "amounts": [20000000000, 30000000000] } ``` ### Response #### Success Response (200) - **poolId** (string) - The address of the newly created AMM pool. - **liquidity** (string) - Identifier for the added liquidity. #### Response Example ```json { "poolId": "0xnew_amm_pool_address", "liquidity": "liquidity_identifier" } ``` ``` -------------------------------- ### Get Campaign Remaining Rewards Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the remaining undistributed rewards for a campaign. ```APIDOC ## GET /campaigns/remaining_rewards ### Description Retrieves the remaining undistributed rewards for a campaign. ### Method GET ### Endpoint `/campaigns/remaining_rewards` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. - **campaignIndex** (u64) - Required - The index of the campaign. ### Request Example ```javascript const remainingRewards = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_remaining_rewards`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **remainingRewards** (u64) - The remaining undistributed rewards for the campaign. ``` -------------------------------- ### GET /view/stable_views/get_position Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves details about a specific position within a stable pool. ```APIDOC ## GET /view/stable_views/get_position ### Description Retrieves details about a specific position within a stable pool. ### Method GET ### Endpoint `/view/stable_views/get_position` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **position_idx** (u64) - Required - The index of the position within the pool. ### Request Example ```javascript const position = await aptos.view({ function: `${viewAddress}::stable_views::get_position`, type_arguments: [], arguments: [poolAddress, positionIndex], }); ``` ### Response #### Success Response (200) - **position** (object) - Details of the position. #### Response Example ```json { "shares": "1000000000000000000" } ``` ``` -------------------------------- ### Pool List Request Example (JSON) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/api Demonstrates the JSON structure for requesting a list of pools from the TAPP Exchange API. It includes parameters for filtering by pool type and pagination settings like page number and page size. ```json { "method": "public/pool", "jsonrpc": "2.0", "id": 3, "params": { "query": { "poolType": "CLMM", "page": 1, "pageSize": 20 } } } ``` -------------------------------- ### Serialize Example Data (TypeScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc This snippet demonstrates serializing basic data types like unsigned 8-bit integers, vectors of account addresses, unsigned 64-bit integers, and unsigned 128-bit integers using a serializer object. It's useful for constructing data payloads for Tapp Exchange interactions. ```typescript ser.serializeU8(3); // V3 ser.serializeVector([ AccountAddress.fromString(coinA), AccountAddress.fromString(coinB), ]); ser.serializeU64(3000); // Fee = 0.3% // initial square root price. ser.serializeU128(sqrtPrice); ``` -------------------------------- ### Creating a Pool Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/amm Details the process and parameters required for creating a new AMM pool. ```APIDOC ## Creating a Pool Pools are created with `create_pool(pool_signer, assets, fee, creator)`. * `pool_signer` is the signer of the newly created account that will store the `Pool` resource. * `assets` is a vector with two addresses representing the coin types of token A and token B. * `fee` must match one of the configured fee tiers (0.01%, 0.05%, 0.3% or 1%). * `creator` is recorded in the `PoolCreated` event. The function initializes reserves to zero and sets `total_shares` to zero. No liquidity exists until someone calls `add_liquidity`. ``` -------------------------------- ### Create CLMM Pool and Add Liquidity Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Establishes a new Concentrated Liquidity Market Maker (CLMM) pool with initial liquidity. It requires token addresses, trading fee, initial amounts, and price range parameters including initial, minimum, and maximum prices. Dependencies include the wallet hook and the SDK's position creation methods. ```typescript const { signAndSubmitTransaction, account } = useWallet(); async function createCLMMPoolAndAddLiquidity() { const params: CreateCLMMPoolAndAddLiquidityParams = { tokenAddress: ['0xtoken1', '0xtoken2'], fee: 3000, amounts: [10000000000, 10000000000], initialPrice: 1, minPrice: 0.000001, maxPrice: Infinity, isMaxAmountB: true, } const data = sdk.Position.createCLMMPoolAndAddLiquidity(params); await signAndSubmitTransaction({ sender: account.address, data: data }); } ``` -------------------------------- ### Get Pool Campaigns Count Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the total number of campaigns associated with a pool. ```APIDOC ## GET /pools/campaigns_count ### Description Retrieves the total number of campaigns associated with a pool. ### Method GET ### Endpoint `/pools/campaigns_count` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. ### Request Example ```javascript const campaignCount = await aptos.view({ function: `${viewAddress}::stable_views::get_pool_campaigns_count`, type_arguments: [], arguments: [poolAddress], }); ``` ### Response #### Success Response (200) - **campaignCount** (u64) - The total number of campaigns in the pool. ``` -------------------------------- ### Get Campaign Total Rewards Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the total rewards allocated to a specific campaign. ```APIDOC ## GET /campaigns/total_rewards ### Description Retrieves the total rewards allocated to a specific campaign. ### Method GET ### Endpoint `/campaigns/total_rewards` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. - **campaignIndex** (u64) - Required - The index of the campaign. ### Request Example ```javascript const totalRewards = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_total_rewards`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **totalRewards** (u64) - The total rewards allocated to the campaign. ``` -------------------------------- ### Fetch Pool Reserves using Aptos View API (JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc An example function demonstrating how to fetch reserve amounts for token A and token B of an AMM pool using the Aptos View API. It calls separate view functions for each reserve. ```javascript async function getPoolReserves(poolAddress) { const reservesA = await aptos.view({ function: `${viewAddress}::amm_views::reserve_a`, type_arguments: [], arguments: [poolAddress], }); const reservesB = await aptos.view({ function: `${viewAddress}::amm_views::reserve_b`, type_arguments: [], arguments: [poolAddress], }); return {reservesA, reservesB}; } ``` -------------------------------- ### Stable Swap Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Documentation for the Stable swap functionality. Currently, specific endpoint details are not provided, but parameter types are outlined. ```APIDOC ## POST /stable/swap ### Description This endpoint facilitates stable-price swaps between tokens in a dedicated stable swap pool. ### Method POST ### Endpoint /stable/swap ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **poolId** (address) - Required - Address of the stable swap pool. - **tokenA** (string) - Required - The symbol or address of the first token in the swap. - **amountA** (u64) - Required - The amount of token A to swap. - **tokenB** (string) - Required - The symbol or address of the second token in the swap. - **minAmountB** (u64) - Required - The minimum amount of token B expected to be received. ### Request Example ```json { "poolId": "0xdef...", "tokenA": "USDC", "amountA": "1000000", "tokenB": "USDT", "minAmountB": "990000" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the swap was successful. - **message** (string) - A confirmation message. - **receivedAmountB** (u64) - The actual amount of token B received. #### Response Example ```json { "success": true, "message": "Stable swap completed.", "receivedAmountB": "995000" } ``` ``` -------------------------------- ### GET /view/stable_views/calculate_pending_rewards Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Calculates pending campaign rewards for a specific position in a stable pool. ```APIDOC ## GET /view/stable_views/calculate_pending_rewards ### Description Calculates pending campaign rewards for a specific position in a stable pool. ### Method GET ### Endpoint `/view/stable_views/calculate_pending_rewards` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **position_idx** (u64) - Required - The index of the position within the pool. ### Request Example ```javascript const rewards = await aptos.view({ function: `${viewAddress}::stable_views::calculate_pending_rewards`, type_arguments: [], arguments: [poolAddress, positionIndex], }); ``` ### Response #### Success Response (200) - **rewards** (vector) - A vector containing the pending campaign rewards. #### Response Example ```json { "rewards": [ { "campaign_id": "0", "amount": "1000000000000000000" } ] } ``` ``` -------------------------------- ### Get Campaign Total Distributed Rewards Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Retrieves the total rewards already distributed in a campaign. ```APIDOC ## GET /campaigns/total_distributed ### Description Retrieves the total rewards already distributed in a campaign. ### Method GET ### Endpoint `/campaigns/total_distributed` ### Query Parameters - **poolAddress** (address) - Required - The address of the pool. - **campaignIndex** (u64) - Required - The index of the campaign. ### Request Example ```javascript const distributedRewards = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_total_distributed`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **distributedRewards** (u64) - The total rewards distributed in the campaign. ``` -------------------------------- ### Calculate Output Amount for Swap (Aptos JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Estimates the output token amount for a given input amount and swap direction within a liquidity pool. Requires the pool's address, input amount, and a boolean indicating the swap direction (A to B or B to A). ```javascript const amountOut = await aptos.view({ function: `${viewAddress}::amm_views::compute_amount_out`, type_arguments: [], arguments: [poolAddress, amountIn, true], }); ``` -------------------------------- ### GET /view/stable_views/position_shares Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Returns the number of shares owned by a specific position within a stable pool. ```APIDOC ## GET /view/stable_views/position_shares ### Description Returns the number of shares owned by a specific position within a stable pool. ### Method GET ### Endpoint `/view/stable_views/position_shares` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **position_idx** (u64) - Required - The index of the position within the pool. ### Request Example ```javascript const shares = await aptos.view({ function: `${viewAddress}::stable_views::position_shares`, type_arguments: [], arguments: [poolAddress, positionIndex], }); ``` ### Response #### Success Response (200) - **shares** (u256) - The number of shares owned by the position. #### Response Example ```json { "shares": "1000000000000000000" } ``` ``` -------------------------------- ### Sign and Submit Swap Transaction (JavaScript) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/api Demonstrates how to sign and submit a transaction to the TAPP Exchange API using JavaScript. It involves converting an unsigned payload to a BCS format, then to a raw transaction, signing it with a wallet, and finally submitting the signed transaction. ```javascript const hexPayload = "this value received from our backend" // Convert bytes to BCS const txSer = Deserializer.fromHex(hexPayload); // Convert BCS to raw transaction const rawTxn = RawTransaction.deserialize(txSer) // Sign and Submit Transaction const simpleTxn = new SimpleTransaction(rawTxn) const response = await aptos.signAndSubmitTransaction({signer: sender, transaction: simpleTxn}); ``` ```javascript const hexPayload = "this value received from our backend" // Convert bytes to BCS const txSer = Deserializer.fromHex(hexPayload); // Convert BCS to raw transaction const rawTxn = RawTransaction.deserialize(txSer) // Sign and Submit Transaction const simpleTxn = new SimpleTransaction(rawTxn) // Use the wallet's signTransaction method to get account authentication const accAuth = await signTransaction(simpleTxn) // Create the transaction builder const signedTxn = new SignedTransaction(rawTxn, accAuth); // full signed transaction const signedTxnBytes = signedTxn.bcsToBytes(); // Convert to hex string const txHex = Buffer.from(signedTxnBytes).toString('hex'); // submit the signed transaction to the backend const response = await fetch('https://api.tapp.exchange/api/v1', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ method: 'public/sc_submit', jsonrpc: '2.0', id: 1, params: { hash: txHex } }) }); ``` -------------------------------- ### Remove Liquidity (AMM) Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc This section details the parameters and examples for removing liquidity from an AMM pool. ```APIDOC ## POST /remove_liquidity ### Description Allows users to remove liquidity from an AMM pool by burning LP tokens. Users can specify minimum amounts of tokens to receive. ### Method POST ### Endpoint /remove_liquidity ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **poolId** (address) - Required - Address of the pool. - **positionAddr** (address) - Required - Address of existing position. - **burnedShares** (u128) - Required - Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool. - **minAmountA** (u64) - Required - Minimum token A amounts to receive when removing liquidity. - **minAmountB** (u64) - Required - Minimum token B amounts to receive when removing liquidity. ### Request Example ```json { "poolId": "0x123...", "positionAddr": "0x456...", "burnedShares": "1000000000000000000", "minAmountA": "1000", "minAmountB": "2000" } ``` ### Response #### Success Response (200) - **amountA** (u64) - Amount of token A received. - **amountB** (u64) - Amount of token B received. #### Response Example ```json { "amountA": "1050", "amountB": "2100" } ``` ``` -------------------------------- ### GET /view/stable_views/get_campaign_rate_per_second Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Returns the emission rate per second for a specific campaign within a stable pool. ```APIDOC ## GET /view/stable_views/get_campaign_rate_per_second ### Description Returns the emission rate per second for a specific campaign within a stable pool. ### Method GET ### Endpoint `/view/stable_views/get_campaign_rate_per_second` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **campaign_idx** (u64) - Required - The index of the campaign. ### Request Example ```javascript const rate = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_rate_per_second`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **rate_per_second** (u64) - The emission rate per second for the campaign. #### Response Example ```json { "rate_per_second": "1000000000000000000" } ``` ``` -------------------------------- ### GET /view/stable_views/get_campaign_token Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sc Returns the reward token address used in a specific campaign within a stable pool. ```APIDOC ## GET /view/stable_views/get_campaign_token ### Description Returns the reward token address used in a specific campaign within a stable pool. ### Method GET ### Endpoint `/view/stable_views/get_campaign_token` ### Parameters #### Query Parameters - **pool_addr** (address) - Required - The address of the pool. - **campaign_idx** (u64) - Required - The index of the campaign. ### Request Example ```javascript const rewardToken = await aptos.view({ function: `${viewAddress}::stable_views::get_campaign_token`, type_arguments: [], arguments: [poolAddress, campaignIndex], }); ``` ### Response #### Success Response (200) - **reward_token_address** (address) - The address of the reward token. #### Response Example ```json { "reward_token_address": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" } ``` ``` -------------------------------- ### Stable Swap Source: https://tapp-exchange.gitbook.io/tapp-exchange/developer-docs/sdk Creates a swap payload for a Stable pool. ```APIDOC ## Stable Swap ### Description Creates a swap payload for a Stable pool. ### Method POST (assumed, as it creates a payload) ### Endpoint /swap/stable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **poolId** (string) - Required - The address of the Stable pool. - **tokenIn** (number) - Required - The Index of the token to swap from. - **tokenOut** (number) - Required - The Index of the token to swap to. - **amountIn** (number) - Required - The input token amount for the swap. - **minAmountOut** (number) - Required - The minimum amount of output tokens. ### Request Example ```json { "poolId": "0xpool", "tokenIn": 2, "tokenOut": 3, "amountIn": 100000000, "minAmountOut": 0 } ``` ### Response #### Success Response (200) - **data** (string) - The transaction payload for the Stable swap. #### Response Example ```json { "data": "transaction_payload_string" } ``` ```