WarpGate SDK is a library that provides a set of tools to interact with the WarpGate protocol. It is built on top of the Uniswap V3 SDK and provides a set of methods to interact with the WarpGate protocol.
Features
Add liquidity to the WarpGate
Remove liquidity from the WarpGate
Increase liquidity positions
Collect fees from positions on WarpGateDex
Table of Contents
Usage
Adding Liquidity to the WarpGate
Removing Liquidity from the WarpGate
Increase LIQUIDITY Positions
Installation
Copy npm install @warpgatex/warpgate-sdk-v3 @uniswap/sdk-core@4.0.9
or
Copy yarn add @warpgatex/warpgate-sdk-v3 @uniswap/sdk-core@4.0.9
Environment Setup
Variables Description Values 13473 (IMX Testnet), 13371 (IMX)
Run tests
To run the streaming intgration tests from this repo:
Copy yarn test:single test/ < filenam e > .spec.ts
Usage
Import the necessary dependencies and create an instance of the liquidityClient
class:
Copy import { liquidityClient } from "@warpgatex/warpgate-sdk-v3" ;
// Create an instance of liquidityClient using a ethers signer
const client = new liquidityClient (signer);
Adding Liquidity to the WarpGate
To add liquidity to the WarpGate, use the mintPosition(...)
method.
Required parameters:
token0: The first token of liquidity pool
token0Amount: The amount of token0 to be added
token1: The second token of liquidity pool
token1Amount: The amount of token1 to be added
poolData: The pool data of the liquidity pool
createPool: Whether to create a new pool or not
Example:
Copy const token0Amount = 100 ;
const token1Amount = 100 ;
const fee = FeeAmount . MEDIUM ;
const token0 = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token1 = new Token (
CHAIN_ID ,
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token0CurrencyAmount = CurrencyAmount .fromRawAmount (
token0 ,
fromReadableAmount (token0Amount , token0 .decimals)
);
const token1CurrencyAmount = CurrencyAmount .fromRawAmount (
token1 ,
fromReadableAmount (token1Amount , token1 .decimals)
);
const poolData = await getPoolData (
token0CurrencyAmount ,
token1CurrencyAmount ,
fee ,
signer .provider
);
const mintPosition = await client .mintPosition (
token0 ,
token0Amount ,
token1 ,
token1Amount ,
poolData .pool ,
poolData .createPool
);
const transaction = {
data : mintPosition .calldata ,
to : NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS ,
value : mintPosition .value ,
from : signer .address ,
gasLimit : 6000000 ,
maxFeePerGas : MAX_FEE_PER_GAS ,
maxPriorityFeePerGas : MAX_PRIORITY_FEE_PER_GAS ,
};
const tx = await signer .sendTransaction (transaction);
console .log (tx);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Removing Liquidity from the WarpGate
To remove liquidity from the WarpGate, use the removeLiquidity()
method.
Required parameters:
positionId: The position id of the liquidity to be removed
token0: The first token of liquidity pool
token1: The second token of liquidity pool
percentage: The percentage of liquidity to be removed (0-1)
recipient: The address to receive the tokens after removing liquidity.
Example:
Copy const positionId = 1 ;
const token0 = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token1 = new Token (
CHAIN_ID ,
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const percentage = 0.5 ;
const recipient = "<recipient_address>" ;
const removeLiquidity = await client .removeLiquidity (
positionId ,
token0 ,
token1 ,
percentage ,
recipient
);
const transaction = {
data : removeLiquidity .calldata ,
to : NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS ,
value : removeLiquidity .value ,
from : signer .address ,
gasLimit : 6000000 ,
maxFeePerGas : MAX_FEE_PER_GAS ,
maxPriorityFeePerGas : MAX_PRIORITY_FEE_PER_GAS ,
};
const tx = await signer .sendTransaction (transaction);
console .log (tx);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Wrap and Unwrap Tokens
To wrap and unwrap tokens, use the wrapNativeToken(...)
and unwrapNativeToken(...)
methods.
Required parameters:
amount: The amount of tokens to be wrapped or unwrapped
Example:
Copy // Wrap tokens
const amount = ethers . utils .parseUnits ( "100" , 18 );
const wrappedTransaction = await client .wrapNativeToken (amount);
console .log ( 'Wrapped Transaction:' , wrappedTransaction);
// Unwrap tokens
const amount = ethers . utils .parseUnits ( "100" , 18 );
const unwrapTransaction = await client .unwrapNativeToken (amount);
console .log ( 'Unwrapped Transaction:' , unwrapTransaction);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Increase LIQUIDITY Positions
To increase liquidity positions, use the increasePosition(...)
method.
Required parameters:
positionId: The position id of the liquidity to be increased
token0: The first token of liquidity pool
token0Amount: The amount of token0 to be added
token1: The second token of liquidity pool
token1Amount: The amount of token1 to be added
Example:
Copy const positionId = 1 ;
const token0 = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token1 = new Token (
CHAIN_ID ,
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token0Amount = 100 ;
const token1Amount = 100 ;
const increasePosition = await client .increasePosition (
positionId ,
token0 ,
token0Amount ,
token1 ,
token1Amount
);
const transaction = {
data : increasePosition .calldata ,
to : NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS ,
value : increasePosition .value ,
from : signer .address ,
gasLimit : 6000000 ,
maxFeePerGas : MAX_FEE_PER_GAS ,
maxPriorityFeePerGas : MAX_PRIORITY_FEE_PER_GAS ,
};
const tx = await signer .sendTransaction (transaction);
console .log (tx);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Swap Tokens
To swap tokens, use the swap(...)
method.
Required parameters:
tokenIn: The token to be swapped
tokenOut: The token to receive
tradeType: The type of trade (exactInput or exactOutput)
tokenAmount: The amount of tokens to be swapped
options: The options for the swap (slippage, deadline)
Example:
Copy const tokenIn = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const tokenOut = new Token (
CHAIN
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const tokenAmount = 100 ;
const tradeType = TradeType . EXACT_INPUT ;
const options = {
slippage : 0.5 ,
deadline : 60 ,
};
const swap = await client .swap (
tokenIn ,
tokenOut ,
tradeType ,
tokenAmount ,
options
);
const transaction = {
data : swap .calldata ,
to : ROUTER_CONTRACT_ADDRESS ,
value : swap .value ,
from : signer .address ,
gasLimit : 6000000 ,
maxFeePerGas : MAX_FEE_PER_GAS ,
maxPriorityFeePerGas : MAX_PRIORITY_FEE_PER_GAS ,
};
const tx = await signer .sendTransaction (transaction);
console .log (tx);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Get Wallet Position IDs
To get the position ids of the wallet, use the getPositionIds(...)
method.
Required parameters:
address: The wallet address having the positions
Example:
Copy const address = "<wallet_address>" ;
const positionIds = await client .getPositionIds (address);
console .log (positionIds);
/* Output
[
BigNumber { _hex: '0x...', _isBigNumber: true },
BigNumber { _hex: '0x...', _isBigNumber: true }
]
*/
Get Position Info
To get the position info, use the getPositionInfo(...)
method.
Required parameters:
positionId: The position id of the liquidity
Copy const positionId = 1 ;
const positionInfo = await client .getPositionInfo (positionId);
console .log (positionInfo);
/* Output
{
positionId: 1,
tickLower: -887272,
tickUpper: -887272,
liquidity: BigNumber { _hex: '0x...' },
tokensOwed0: BigNumber { _hex: '0x...' },
tokensOwed1: BigNumber { _hex: '0x...' }
token0: '0x...',
token1: '0x...'
fee: 3000
tokenAmount0: BigNumber { _hex: '0x...' },
tokenAmount1: BigNumber { _hex: '0x...' },
currentPrice: 1,
lowerRangePrice: 2e-6,
upperRangePrice: 2e+6
}
*/
Get Quote for Swap
To get the quote for swap, use the getQuote(...)
method.
Required parameters:
tokenIn: The token to be swapped
tokenOut: The token to receive
tradeType: The type of trade (exactInput or exactOutput)
tokenAmount: The amount of tokens to be swapped
slippage: The slippage for the swap
Example:
Copy const tokenIn = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const tokenOut = new Token (
CHAIN
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const tokenAmount = "1000" ;
const tradeType = TradeType . EXACT_INPUT ;
const slippage = 0.005 ; // 0.5%
const quote = await client .getQuote (
tokenIn ,
tokenOut ,
tradeType ,
tokenAmount ,
slippage
);
console .log (quote);
/* Output
{
exchangeRate: 0.0001,
priceImpact: 0.0001,
route: [
RouteV3 {
_midPrice: [Price],
pools: [Array],
input: [Token],
output: [Token],
protocol: 'V3',
path: [Array],
}
]
}
*/
Collect Fees
To collect fees, use the collectFees(...)
method.
Required parameters:
positionId: The position id of the liquidity
token0: The first token of liquidity pool
token1: The second token of liquidity pool
recipient: The address to receive the fees
Example:
Copy const positionId = 1 ;
const token0 = new Token (
CHAIN_ID ,
"<token0_address>" ,
18 ,
"Symbol" ,
"Name"
);
const token1 = new Token (
CHAIN_ID ,
"<token1_address>" ,
18 ,
"Symbol" ,
"Name"
);
const recipient = "<recipient_address>" ;
const collectFees = await client .collectFees (
positionId ,
token0 ,
token1 ,
recipient
);
const transaction = {
data : collectFees .calldata ,
to : NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS ,
value : collectFees .value ,
from : signer .address ,
gasLimit : 6000000 ,
maxFeePerGas : MAX_FEE_PER_GAS ,
maxPriorityFeePerGas : MAX_PRIORITY_FEE_PER_GAS ,
};
const tx = await signer .sendTransaction (transaction);
console .log (tx);
/* Output
{
hash: '0x...',
blockHash: '0x...',
blockNumber: 123,
transactionIndex: 1,
confirmations: 1,
from: '0x...',
gasPrice: '0x...',
gasLimit: '0x...',
to: '0x...',
value: '0x...',
nonce: 1,
data: '0x...',
r: '0x...',
s: '0x...',
v: '0x...',
creates: null,
chainId: 1,
wait: [Function (anonymous)]
}
*/
Contributing
Contributions are welcome! If you find any issues or have suggestions, please open an issue or submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details