Use MoonShot

The Use MoonShot tool, part of AgentiPy, allows users to interact with the Moonshot protocol on Solana. Moonshot appears to be a decentralized exchange (DEX) that uses a bonding curve mechanism. This tool provides functionalities to buy and sell tokens against a collateral asset (likely SOL) on this curve.

Functionality

This tool is implemented in the MoonshotManager class. It interacts directly with the Moonshot on-chain program (MOONSHOT_PROGRAM) by constructing and sending Solana transactions.

Key Methods:

  • buy(agent: SolanaAgentKit, mint_str: str, collateral_amount: float = 0.01, slippage_bps: int = 500):

    • Buys tokens from a Moonshot curve.

    • Parameters:

      • agent: The SolanaAgentKit instance.

      • mint_str: The mint address (string) of the token to buy.

      • collateral_amount: The amount of collateral (SOL) to spend (default 0.01 SOL).

      • slippage_bps: Slippage tolerance in basis points (default 500 = 5%).

    • Calculates the expected token amount using get_tokens_by_collateral_amount.

    • Constructs a transaction with instructions to set compute unit price/limit and the swap instruction for the Moonshot program.

    • Handles creation of the Associated Token Account (ATA) for the user if it doesn't exist.

    • Signs and sends the transaction.

  • sell(agent: SolanaAgentKit, mint_str: str, token_balance: float = None, slippage_bps: int = 500):

    • Sells tokens to a Moonshot curve.

    • Parameters:

      • agent: The SolanaAgentKit instance.

      • mint_str: The mint address (string) of the token to sell.

      • token_balance: The amount of tokens to sell. If None, it attempts to fetch the full balance of the token for the agent's wallet.

      • slippage_bps: Slippage tolerance in basis points (default 500 = 5%).

    • Calculates the expected collateral amount to receive using get_collateral_amount_by_tokens.

    • Constructs and sends the transaction similarly to the buy method.

Constants used (from agentipy.utils.moonshot.constants):

  • MOONSHOT_PROGRAM: The on-chain program ID for Moonshot.

  • LAMPORTS_PER_SOL, DEX_FEE, HELIO_FEE, CONFIG_ACCOUNT, TOKEN_PROGRAM, ASSOC_TOKEN_ACC_PROG, SYSTEM_PROGRAM.

  • UNIT_PRICE, UNIT_BUDGET: Compute unit settings.

Important Considerations:

  • Direct On-Chain Interaction: This tool interacts directly with the Solana blockchain by sending transactions to the Moonshot program. It does not use a proxy.

  • Financial Risk: Trading on DEXs like Moonshot involves financial risks, including price volatility, slippage, and potential smart contract vulnerabilities. Curve-based DEXs can have unique price dynamics.

  • Token Mints: You need the correct mint address of the token traded on Moonshot.

  • Associated Token Accounts: The tool handles the creation of Associated Token Accounts (ATAs) if they don't exist for the agent's wallet.

  • Transaction Confirmation: The script includes a confirm_txn utility (not shown in the snippet but present in the file) which should be used to ensure transactions are finalized. The example above simplifies this.

Source Code

You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_moonshot.py

Last updated