npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@warpgatex/warpgate-sdk-v3

v2.0.9

Published

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.

Downloads

852

Readme

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/[email protected]

or

yarn add @warpgatex/warpgate-sdk-v3 @uniswap/[email protected]

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