@warpgatex/warpgate-sdk-v3
TypeScript icon, indicating that this package has built-in type declarations

2.0.9 • Public • Published

WarpGate SDK

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
  • Wrap and unwrap tokens
  • Increase liquidity positions
  • Swap tokens
  • Get wallet position IDs
  • Get position info
  • Get quote for swap
  • Collect fees from positions on WarpGateDex

Table of Contents

Installation

npm install @warpgatex/warpgate-sdk-v3 @uniswap/sdk-core@4.0.9

or

yarn add @warpgatex/warpgate-sdk-v3 @uniswap/sdk-core@4.0.9

Environment Setup

Variables Description Values
CHAIN_ID Chain Id 13473 (IMX Testnet), 13371 (IMX)

Run tests

To run the streaming intgration tests from this repo:

yarn test:single test/<filename>.spec.ts

Usage

Import the necessary dependencies and create an instance of the liquidityClient class:

import { liquidityClient } from "@warpgatex/warpgate-sdk-v3";

// Create an instance of liquidityClient using a ethers signer
const client = new liquidityClient(signer, CHAIN_ID);

Adding Liquidity to the WarpGate

To add liquidity to the WarpGate, use the mintPosition(...) method.

Required parameters:

  1. token0: The first token of liquidity pool
  2. token0Amount: The amount of token0 to be added
  3. token1: The second token of liquidity pool
  4. token1Amount: The amount of token1 to be added
  5. poolData: The pool data of the liquidity pool
  6. createPool: Whether to create a new pool or not

Example:

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[CHAIN_ID],
  value: mintPosition.value,
  from: signer.address,
  gasLimit: 6000000,
  maxFeePerGas: MAX_FEE_PER_GAS[CHAIN_ID],
  maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS[CHAIN_ID],
};
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:

  1. positionId: The position id of the liquidity to be removed
  2. token0: The first token of liquidity pool
  3. token1: The second token of liquidity pool
  4. percentage: The percentage of liquidity to be removed (0-1)
  5. recipient: The address to receive the tokens after removing liquidity.

Example:

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[CHAIN_ID],
  value: removeLiquidity.value,
  from: signer.address,
  gasLimit: 6000000,
  maxFeePerGas: MAX_FEE_PER_GAS[CHAIN_ID],
  maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS[CHAIN_ID],
};
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:

  1. amount: The amount of tokens to be wrapped or unwrapped

Example:

// 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:

  1. positionId: The position id of the liquidity to be increased
  2. token0: The first token of liquidity pool
  3. token0Amount: The amount of token0 to be added
  4. token1: The second token of liquidity pool
  5. token1Amount: The amount of token1 to be added

Example:

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[CHAIN_ID],
  value: increasePosition.value,
  from: signer.address,
  gasLimit: 6000000,
  maxFeePerGas: MAX_FEE_PER_GAS[CHAIN_ID],
  maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS[CHAIN_ID],
};
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:

  1. tokenIn: The token to be swapped
  2. tokenOut: The token to receive
  3. tradeType: The type of trade (exactInput or exactOutput)
  4. tokenAmount: The amount of tokens to be swapped
  5. options: The options for the swap (slippage, deadline)

Example:

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[CHAIN_ID],
  value: swap.value,
  from: signer.address,
  gasLimit: 6000000,
  maxFeePerGas: MAX_FEE_PER_GAS[CHAIN_ID],
  maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS[CHAIN_ID],
};
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:

  1. address: The wallet address having the positions

Example:

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:

  1. positionId: The position id of the liquidity
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:

  1. tokenIn: The token to be swapped
  2. tokenOut: The token to receive
  3. tradeType: The type of trade (exactInput or exactOutput)
  4. tokenAmount: The amount of tokens to be swapped
  5. slippage: The slippage for the swap

Example:

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:

  1. positionId: The position id of the liquidity
  2. token0: The first token of liquidity pool
  3. token1: The second token of liquidity pool
  4. recipient: The address to receive the fees

Example:

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[CHAIN_ID],
  value: collectFees.value,
  from: signer.address,
  gasLimit: 6000000,
  maxFeePerGas: MAX_FEE_PER_GAS[CHAIN_ID],
  maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS[CHAIN_ID],
};
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

Readme

Keywords

none

Package Sidebar

Install

npm i @warpgatex/warpgate-sdk-v3

Weekly Downloads

151

Version

2.0.9

License

ISC

Unpacked Size

161 kB

Total Files

35

Last publish

Collaborators

  • subasshrestha
  • warpgate