Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator strips away existing code leaving a placeholder comment instead #3048

Open
karlbenoit opened this issue Nov 23, 2024 · 1 comment

Comments

@karlbenoit
Copy link

Describe the bug

The rest of the file is replaced by this commend: // Rest of the file remains the same...

import { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
import { useHttpLogger } from './httpLogger';
import { useWalletStore } from '../store/useWalletStore';

const JUPITER_API_BASE = 'https://quote-api.jup.ag/v6';

interface SwapInfo {
  ammKey: string;
  label: string;
  inputMint: string;
  outputMint: string;
  inAmount: string;
  outAmount: string;
  feeAmount: string;
  feeMint: string;
}

interface RoutePlan {
  swapInfo: SwapInfo;
  percent: number;
}

export interface SwapRoute {
  inputMint: string;
  inAmount: string;
  outputMint: string;
  outAmount: string;
  otherAmountThreshold: string;
  swapMode: string;
  slippageBps: number;
  platformFee: any;
  priceImpactPct: string;
  routePlan: RoutePlan[];
  contextSlot: number;
  timeTaken: number;
}

export interface SwapQuote {
  routes: SwapRoute[];
  selectedRoute: number;
}

export interface SwapParams {
  fromToken: string;
  toToken: string;
  amount: number;
  slippage: number;
}

const isValidSolanaAddress = (address: string): boolean => {
  return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
};

export async function getSwapQuote(
  connection: Connection,
  params: SwapParams,
  endpointName: string
): Promise<SwapQuote> {
  const logger = useHttpLogger.getState();
  const requestId = Math.random().toString(36).substring(7);

  try {
    // Validate addresses
    if (!isValidSolanaAddress(params.fromToken) || !isValidSolanaAddress(params.toToken)) {
      throw new Error('Invalid token address format');
    }

    logger.addLog({
      id: requestId,
      timestamp: Date.now(),
      type: 'quote',
      data: {
        step: 'request',
        message: 'Requesting swap quote',
        params,
        endpoint: endpointName
      }
    });

    // Convert amount to proper units (assuming 9 decimals for now)
    const amountInLamports = Math.floor(params.amount * 1e9).toString();
    const slippageBps = Math.floor(params.slippage * 100).toString();

    const queryParams = new URLSearchParams({
      inputMint: params.fromToken,
      outputMint: params.toToken,
      amount: amountInLamports,
      slippageBps,
      onlyDirectRoutes: 'true'
    });

    const url = `${JUPITER_API_BASE}/quote?${queryParams.toString()}`;

    logger.addLog({
      id: requestId,
      timestamp: Date.now(),
      type: 'quote',
      data: {
        step: 'request_sent',
        message: 'Sending quote request',
        url
      }
    });

    const response = await fetch(url);
    const responseText = await response.text();

    if (!response.ok) {
      throw new Error(`Failed to get quote: ${responseText}`);
    }

    let quoteResponse;
    try {
      quoteResponse = JSON.parse(responseText);
    } catch (e) {
      throw new Error(`Failed to parse quote response: ${responseText}`);
    }

    logger.addLog({
      id: requestId,
      timestamp: Date.now(),
      type: 'quote',
      data: {
        step: 'response_received',
        message: 'Received quote response',
        response: quoteResponse
      }
    });

    // For now, we'll treat the single response as our only route
    const quote: SwapQuote = {
      routes: [quoteResponse],
      selectedRoute: 0
    };

    logger.addLog({
      id: requestId,
      timestamp: Date.now(),
      type: 'quote',
      data: {
        step: 'quote_parsed',
        message: 'Quote parsed successfully',
        routeCount: 1,
        bestRoute: quoteResponse
      }
    });

    return quote;
  } catch (error) {
    logger.addLog({
      id: requestId,
      timestamp: Date.now(),
      type: 'quote',
      data: {
        step: 'error',
        message: 'Failed to get quote',
        error: error instanceof Error ? error.message : 'Unknown error'
      }
    });
    throw error;
  }
}

// Rest of the file remains the same...

Link to the Bolt URL that caused the error

https://bolt.new/~/sb1-wunplo

Steps to reproduce

enter prompt: now i get :Failed to get quote: {"error":"Query parameter outputMint cannot be parsed: WrongSize"}

Expected behavior

correct the problematic function leaving the remaining code in the file untouched

Screen Recording / Screenshot

No response

Platform

Browser name = Chrome
Full version = 131.0.0.0
Major version = 131
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 253858536,
  "usedJSHeapSize": 161686200,
  "jsHeapSizeLimit": 4294705152
}
Username = tuxman
Chat ID = a29ea0c9ea11

Additional context

No response

@TableflipFoundry
Copy link

This is also happening to me.
It is incredibly problematic.
I have a shortcut that I had to make to start adding this to the end of my prompts. Give it a try.

Don't use any code placeholders, make sure to edit completely and not partially. Make sure you're checking your work for errors.
Do not edit unnecessary bits of code, or files. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants