> For the complete documentation index, see [llms.txt](https://docs.agentipy.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agentipy.fun/tools/use-moonshot.md).

# 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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agentipy.fun/tools/use-moonshot.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
