Bot SDK - Base

Calculate prices and prepare buy/sell transactions via the Moonshot SDK

Join our developer TG channel for important updates.

The trading instructions for buy and sell (but not mint) are directly available on-chain via the Moonshot Smart Contract.

Overview

The Moonshot SDK for EVM provides the following functions:

  • Get price of the token / position on bonding curve

  • Calculate collateral/token in and out

  • Generate buy and sell transactions (both exact in and out)

  • Set the slippage amount

Installation

Install the package using npm or yarn

Copy

npm i @wen-moon-ser/moonshot-sdk-evm
# or
yarn add @wen-moon-ser/moonshot-sdk-evm

https://github.com/wen-moon-ser/moonshot-sdk-evm/tree/implementation?tab=readme-ov-filegithub.comExample in Wen Moon repo

Initializing Moonshot

To initialize the Moonshot SDK, you need to create an instance of the Moonshot class. Before instantiating the Moonshot class, define your rpcUrl and signer.

Public endpoints for rpcUrl

Parameters of the Moonshot class

  • environment : You can initialize the environment for either mainnet or devnet

    • For Mainnet, use Environment.Mainnet

    • For Devnet, use Environemnt.Testnet

  • signer : generated through your private key and rpcUrl

Copy

import { Wallet } from 'ethers';
import { JsonRpcProvider } from 'ethers';
import { Moonshot, Token, FixedSide, Environment } from '@wen-moon-ser/moonshot-sdk-evm';

export const buyTx = async (): Promise<void> => {
  console.log('--- Buying token example ---');

  const rpcUrl = 'https://base-sepolia.gateway.tenderly.co';

  const provider = new JsonRpcProvider(rpcUrl);
  const signer = new Wallet('private key', provider);

  const moonshot = new Moonshot({
      signer: signer,
      env: Environment.Testnet,
  });

Buy Example

Copy

import { Wallet } from 'ethers';
import { JsonRpcProvider } from 'ethers';
import { Moonshot, Token, FixedSide, Environment } from '@wen-moon-ser/moonshot-sdk-evm';

export const buyTx = async (): Promise<void> => {
  console.log('--- Buying token example ---');

  const rpcUrl = 'https://base-sepolia.gateway.tenderly.co';

  const provider = new JsonRpcProvider(rpcUrl);
  const signer = new Wallet('private key', provider);

  const moonshot = new Moonshot({
      signer: signer,
      env: Environment.Testnet,
  });

  const token = await Token.create({
    tokenAddress: '0x1234567890123456789012345678901234567890',
    moonshot,
  });

  const tokenAmount = 10000n * 10n ** 18n; // Buy 10k tokens
  const collateralAmount = await token.getCollateralAmountByTokens({
    tokenAmount,
    tradeDirection: 'BUY',
  });

  const tx = await token.prepareTx({
    slippageBps: 500,
    tokenAmount,
    collateralAmount,
    tradeDirection: 'BUY',
    fixedSide: FixedSide.OUT,
  });
  tx.from = await signer.getAddress();

  const gas = await provider.estimateGas(tx);
  const feeData = await provider.getFeeData();

  tx.gasLimit = gas;
  tx.gasPrice = feeData.gasPrice!;

  const txHash = await signer.sendTransaction(tx);
  console.log('Transaction hash:', txHash);
};

Sell Example

Copy

import { Wallet } from 'ethers';
import { JsonRpcProvider } from 'ethers';
import { Moonshot, Token, FixedSide } from '@wen-moon-ser/moonshot-sdk-evm';

export const buyTx = async (): Promise<void> => {
  console.log('--- Buying token example ---');

  const rpcUrl = 'https://base-sepolia.gateway.tenderly.co'

  const provider = new JsonRpcProvider(rpcUrl);
  const signer = new Wallet('private key', provider);

  const moonshot = new Moonshot({
      signer: signer,
      env: Environment.Testnet,
  });

  const token = await Token.create({
    tokenAddress: '0x1234567890123456789012345678901234567890',
    moonshot,
  });

  const tokenAmount = 10000n * 10n ** 18n; // Buy 10k tokens
  const collateralAmount = await token.getCollateralAmountByTokens({
    tokenAmount,
    tradeDirection: 'SELL',
  });

  const tx = await token.prepareTx({
    slippageBps: 500,
    tokenAmount,
    collateralAmount,
    tradeDirection: 'SELL',
    fixedSide: FixedSide.OUT,
  });

  tx.from = await signer.getAddress();

  const gas = await provider.estimateGas(tx);
  const feeData = await provider.getFeeData();

  tx.gasLimit = gas;
  tx.gasPrice = feeData.gasPrice!;

  const txHash = await signer.sendTransaction(tx);
  console.log('Transaction hash:', txHash);
};

Last updated