VinuSwap Class

The main class for interacting with VinuSwap contracts.

Constructor

The VinuSwap class uses a factory pattern:

static async create(
    tokenA: string,
    tokenB: string,
    poolAddress: string,
    quoterAddress: string,
    routerAddress: string,
    positionManagerAddress: string,
    signerOrProvider: Signer | Provider
): Promise<VinuSwap>

Parameters

Parameter
Type
Description

tokenA

string

First token address

tokenB

string

Second token address

poolAddress

string

Pool contract address

quoterAddress

string

Quoter contract address

routerAddress

string

SwapRouter address

positionManagerAddress

string

Position manager address

signerOrProvider

Signer | Provider

ethers signer or provider

Example

Properties

Contract References

Token Addresses (Getters)

Methods

connect

Connects a signer for transaction signing.

Returns a new VinuSwap instance with the signer attached.


Pool Query Methods

price

Gets the current price ratio (token1/token0).

poolFee

Gets the pool fee in bips (0.01%).

locked

Checks if the pool is locked.

factory

Gets the factory address that created the pool.

balance0 / balance1

Gets the token balances of the pool.

protocolShare0 / protocolShare1

Gets the protocol fee share for each token.

availableProtocolFees

Gets collected protocol fees.


Swap Methods

quoteExactInput

Gets a quote for swapping an exact input amount.

Returns the expected output amount as a string.

Example:

swapExactInput

Swaps an exact input amount for a minimum output (requires signer).

Example:

quoteExactOutput

Gets a quote for the input needed to receive an exact output.

Returns the required input amount as a string.

swapExactOutput

Swaps up to a maximum input for an exact output amount (requires signer).


Position Methods

positionIdsByOwner

Gets all position NFT IDs owned by an address.

positionOwner

Gets the owner of a position.

positionOperator

Gets the approved operator for a position.

positionLiquidity

Gets the liquidity of a position.

positionAmount0 / positionAmount1

Gets the token amounts in a position.

positionPriceBounds

Gets the price range bounds of a position.

Returns [lowerPriceBound, upperPriceBound] as strings.

positionTokensOwed

Gets uncollected tokens owed to a position.

positionLockedUntil

Gets the lock expiration date (or null if never locked).

positionIsLocked

Checks if a position is currently locked.

positionTokenURI

Gets the token URI for a position NFT.


Liquidity Methods

mint

Creates a new liquidity position using price ratios (requires signer).

Parameters:

Parameter
Type
Description

ratioLower

number

Lower price ratio (token1/token0)

ratioUpper

number

Upper price ratio (token1/token0)

amount0Desired

BigNumberish

Desired token0 amount

amount1Desired

BigNumberish

Desired token1 amount

slippageRatio

number

Slippage tolerance (0-1, e.g., 0.005 for 0.5%)

recipient

string

NFT recipient address

deadline

Date

Transaction deadline

Example:

quoteMint

Quotes the amounts that will be used when minting.

increaseLiquidity

Adds liquidity to an existing position (requires signer).

quoteIncreaseLiquidity

Quotes the amounts that will be added.

decreaseLiquidity

Removes liquidity from a position (requires signer).

Note: Tokens are not transferred directly. Call collect() to receive them.

quoteDecreaseLiquidity

Quotes the amounts that will be removed.

collect

Collects tokens owed from a position (requires signer).

burn

Burns a position NFT (requires signer).

Note: Position must have zero liquidity and zero tokens owed.

lock

Locks a position until a specified date (requires signer).


Protocol Methods

collectProtocol

Collects protocol fees (requires appropriate permissions).


Usage Examples

Complete Swap Flow

Complete Liquidity Flow

Position Locking

Error Handling

Last updated