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

@zuludmmswap/zs-sdk-solana

v1.0.0

Published

```typescript import { AnchorProvider } from '@project-serum/anchor'

Downloads

2

Readme

Creating a AnchorProvider instance

import { AnchorProvider } from '@project-serum/anchor'

const anchorProvider = AnchorProvider.env()

Creating a Router instance

const router = new Router(
  new Context(
    anchorProvider,
    'ZuluSwapFactory111111111111111111111111111',
    'ZuluSwapPooL111111111111111111111111111111',
    'ZuluSwapRouter1111111111111111111111111111',
  ),
  new PublicKey(process.env.ROUTER_STATE_ADDRESS!),
)

Examples

  • Put addresses into examples/.env file
    • Required: ANCHOR_PROVIDER_URL, ANCHOR_WALLET, ZULUSWAP_POOL_PROGRAM, ZULUSWAP_FACTORY_PROGRAM, ZULUSWAP_ROUTER_PROGRAM, FACTORY_STATE_ADDRESS, ROUTER_STATE_ADDRESS
    • E.g
ANCHOR_PROVIDER_URL=https://api.testnet.solana.com
ANCHOR_WALLET=/Users/username/.config/solana/id.json
ZULUSWAP_POOL_PROGRAM=5ep1RDH89G1edSjJCqDzamXBg2yXNEZTxwAReD3FWa8j
ZULUSWAP_FACTORY_PROGRAM=HuRvNfEovfUomar3qNhngZc34EygX9kHNfujhwF1YLjz
ZULUSWAP_ROUTER_PROGRAM=3EN91sb7qdzSMPJZEkSUey1oe4hHEDFar1Kp3jTZWyhg
FACTORY_STATE_ADDRESS=HWoZFnLkKeGHrHwu9sySFts3oTVfDfQ9TnwXEqpSGU5D
ROUTER_STATE_ADDRESS=ASBnocaA9kg8QgyZZ23o7C9scVrxPaWZVLP1PEwhyqBw
COMMITMENT_LEVEL=confirmed
KNC_MINT=KNCVyKuChfKTLDJ3EQEatqF4kBEF2PNECoTRWsx5qXz
ETH_MINT=ETHTjGKn8ze4Cbk3tWK6MKAV5v3xswpCvbXo1mQapzn8
BNB_MINT=BNBbo7KptCeBm9eZFHeUTSLwtxTJTAwsZr6yYri497jg
BTC_MINT=BTCfmTMzFeV4BNvCiyTVVR1XaQPMvsrrdyjJeuE4VdEm
  • To ensure token accounts have been created, run spl-token accounts

  • Run yarn run ts-node examples/{THE_EXAMPLE_TO_RUN_FILENAME}.ts

Add Liquidity New Pool

  • Call Router's method addLiquidityNewPool to construct a ready-to-send transaction
const tx = await router.addLiquidityNewPool(
  anchorProvider.wallet.publicKey,
  KNC,
  BNB,
  20000,
  1,
  kncAmount,
  bnbAmount,
  new BN(0),
  new BN(0),
)
  • Because AddLiquidityNewPool needs more than 400_000 compute units, we should request more compute unit
    • Use method createRequestUnitsInstruction to construct a request CU instruction
    • Put request CU instruction to the current transaction's instruction list
tx.instructions = [createRequestUnitsInstruction(Router.ADD_LIQUIDITY_NEW_POOL_COMPUTE_BUDGET, 0), ...tx.instructions]

Add Liquidity

  • Call Router's method addLiquidity to construct a ready-to-send transaction
const tx = await router.addLiquidity(
  poolStateAddress,
  anchorProvider.wallet.publicKey,
  KNC,
  kncAmount,
  bnbAmount,
  new BN(0),
  new BN(0),
)

Remove Liquidity

  • Call Router's method removeLiquidity to construct a ready-to-send transaction
const tx = await router.removeLiquidity(
  poolStateAddress,
  anchorProvider.wallet.publicKey,
  KNC,
  liquidityAmount,
  new BN(0),
  new BN(0),
)

Swap

  • Call Router's method swap to construct a ready-to-send transaction
const tx = await router.swap(anchorProvider.wallet.publicKey, trade, {
  allowedSlippage: new Percent('1', '100'),
})

Send transaction

  • Use method sendAndConfirmTransaction to sign transaction (using Wallet) then send to nodes and wait for confirmation
const txHash = await sendAndConfirmTransaction(anchorProvider, tx)
  • A transaction hash will be returned if the transaction's successful