0.0.9 • Published 11 days ago

heaven-sdk v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

Valhalla SDK

Usage

Create a new mint (example)

const connection = new Connection(
		HeavenSupportedNetworkClusterApiUrl[HeavenSupportedNetwork.localnet],
		'confirmed'
	);
const mint = Keypair.generate();
const createMintIx =
    await Heaven.makeCreateToken2022WithTransferFeeInstruction({
        connection,
        decimals: 9,
        feeBasisPoints: 100,
        maxFee: BigInt(100),
        mintAuthority: payer.publicKey,
        payer: payer.publicKey,
        transferFeeConfigAuthority: payer.publicKey,
        withdrawWithheldAuthority: payer.publicKey,
        freezeAuthority: payer.publicKey,
        userDefinedMint: mint.publicKey,
    });

const createMintTx = await sendAndConfirmTransaction(
    connection,
    createMintIx,
    [payer, mint],
    {
        commitment: 'confirmed',
        preflightCommitment: 'confirmed',
    }
);

Create a new pool (example)

Parameters

  • encodedUserDefinedEventData: A base64 encoded string that can be used to store any data you want to emit when the pool is created.
  • expectedBaseTokenBalanceAfterTransferFee: The expected balance of the base token after the transfer fee(if any).
  • expectedQuoteTokenBalanceAfterTransferFee: The expected balance of the quote token after the transfer fee(if any).
  • inputBaseTokenAmount: The amount of base token to deposit.
  • inputQuoteTokenAmount: The amount of quote token to deposit.
  • lockLiquidityProviderTokenUntil: The unix timestamp in seconds until which the liquidity provider tokens will be locked.
  • openAt: The unix timestamp in seconds at which the pool will be open for trading.
  • swapTaxDenominator: A non-zero swap tax denominator.
  • swapTaxNumerator: A swap tax numerator.
  • taxationMode:
    • None: No tax will be applied.
    • Input: Tax will be applied on whatever the input (Base/Quote) token.
    • Base: Tax will be applied on only the Base token.
    • Quote: Tax will be applied on only the Quote token.
const createLiquidityPoolIx = await pool
    .makeCreateLiquidityPoolInstruction({
      encodedUserDefinedEventData: "",
      expectedBaseTokenBalanceAfterTransferFee: new BN(1000_000 * 1e9),
      expectedQuoteTokenBalanceAfterTransferFee: new BN(1000 * 1e9),
      inputBaseTokenAmount: new BN(1000_000 * 1e9),
      inputQuoteTokenAmount: new BN(1000 * 1e9),
      lockLiquidityProviderTokenUntil: locked
        ? new BN(Math.ceil(Date.now() / 1000 + 1 * 60))
        : new BN(0),
      openAt: new BN(0),
      swapTaxDenominator: new BN(100),
      swapTaxNumerator: new BN(25),
      taxationMode: {
        input: {},
      },
    })
    .instruction();

const createLiquidityPoolTx = await sendAndConfirmTransaction(
    connection,
    new Transaction().add(
      ...[
        anchor.web3.ComputeBudgetProgram.setComputeUnitLimit({
          units: 300000,
        }),
        createLiquidityPoolIx,
      ]
    ),
    [owner],
    {
      commitment: "confirmed",
      preflightCommitment: "confirmed",
      skipPreflight: true,
    }
  );