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

@lyfebloc/lb-sdk-solana

v9.0.0

Published

an sdk for amm on solana

Downloads

3

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,
    'LyfeblocFactory111111111111111111111111111',
    'LyfeblocPooL111111111111111111111111111111',
    'LyfeblocRouter1111111111111111111111111111',
  ),
  new PublicKey(process.env.ROUTER_STATE_ADDRESS!),
)

Examples

  • Put addresses into examples/.env file
    • Required: ANCHOR_PROVIDER_URL, ANCHOR_WALLET, LYFEBLOC_POOL_PROGRAM, LYFEBLOC_FACTORY_PROGRAM, LYFEBLOC_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
LYFEBLOC_POOL_PROGRAM=675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8
LYFEBLOC_FACTORY_PROGRAM=5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h
LYFEBLOC_ROUTER_PROGRAM=routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS
FACTORY_STATE_ADDRESS=HWoZFnLkKeGHrHwu9sySFts3oTVfDfQ9TnwXEqpSGU5D
ROUTER_STATE_ADDRESS=ASBnocaA9kg8QgyZZ23o7C9scVrxPaWZVLP1PEwhyqBw
COMMITMENT_LEVEL=confirmed
SOL_MINT=So11111111111111111111111111111111111111112
RAY_MINT=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
  • 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,
  RAY,
  SOL,
  20000,
  1,
  rayAmount,
  solAmount,
  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,
  RAY,
  rayAmount,
  solAmount,
  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,
  RAY,
  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