Liquidity
By using these liquidity-related functions, you can fully manage your liquidity positions: create pools, add or remove liquidity within precise price ranges, and collect accrued fees.
createPoolV3
Creates a new Pool (if it does not already exist) and initializes it with a desired starting price.
const createPoolV3 = async (
token0: string,
token1: string,
desirePrice: number,
fee: 500 | 3000 | 10000
)Parameters:
token0/token1: Addresses of the tokens in the desired pool.desirePrice: The initial price you want when the pool is created.fee: The fee tier for the pool (500for 0.05%,3000for 0.3%, or10000for 1%).
Returns:
On success, returns a transaction hash (as a
stringor ethersTransactionResponse).On failure, returns an
Error.
Usage Example:
import { createPoolV3, ADDRESSES } from '@storyhunt/wrapper-sdk';
async function createNewPool() {
const txHash = await createPoolV3(
ADDRESSES.TOKENS.WIP.id, // token0
ADDRESSES.TOKENS.USDC.id, // token1
1000, // desirePrice
3000 // fee tier
);
console.log('Transaction result:', txHash);
}addLiquidityV3
Adds liquidity to an existing Pool between two tokens, specifying a price range.
Parameters:
token0/token1: The token addresses for the pool (use WIP address if IP is involved).fee: The poolβs fee tier.amount0/amount1: Decimal amounts of each token to deposit.highPrice/lowPrice: Defines the upper and lower price boundaries for your liquidity.
Returns:
A transaction hash or an ethers
TransactionResponseif successful.An
Errorif the operation fails.
Usage Example:
addPositionLiquidityV3
Increases the liquidity of an existing position identified by positionId.
Parameters:
positionId: The StroyHunt V3 position (NFT) ID you want to add liquidity to.amount0/amount1: Decimal amounts of token0 and token1 to add.
Returns:
A transaction hash or
TransactionResponseif successful.An
Erroron failure.
Usage Example:
removeLiquidityV3
Removes a specified percentage of liquidity from an existing position.
Parameters:
positionId: The ID (NFT) of the position from which to remove liquidity.percentageToRemove: A number between 0 and 100 indicating how much of the current liquidity to remove.
Returns:
A transaction hash or
TransactionResponseif successful.An
Errorif removal fails.
Usage Example:
collectFeeV3
Collects fees accrued in a given position.
Parameters:
positionId: The ID of the liquidity position (NFT) from which to collect fees.
Returns:
A transaction hash or
TransactionResponseif successful.An
Errorif the fee collection fails.
Usage Example:
getUserPoolsV3
Function:
Retrieves all liquidity positions (pools) associated with the connected user by executing a GraphQL query against the subgraph.
Parameters:
None
Returns:
GraphPositionResponse: An object containing the user's liquidity positions, including details such as token addresses, liquidity amounts, tick ranges, and associated pools.Error: An error object if the query fails or if no connected address is found.
Example:
Token Approval
V3 Non-Fungible Position Manager Approval
Function:
Approves the Non-Fungible Position Manager to spend your tokens. Defaults to MaxUint256 if amount is not provided.
Example: