Skip to content

check native src tx cost #67

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

SevenSwen
Copy link
Contributor

No description provided.

This comment was marked as outdated.

Copy link

Summary:

The code change adds a new test case to the fusion-swap.ts test suite, which calculates and prints the transaction cost when the source asset is the native SOL token (native source). The test sets up an order with srcMint set to NATIVE_MINT and srcAssetIsNative set to true. It constructs a transaction that transfers lamports to Alice's associated token account (ATA) for the native mint, synchronizes the native account, executes the create instruction of the program, and finally prints the transaction costs.

Issues and Suggestions:

  1. Missing Associated Token Account for Native Mint

    Issue: The test assumes that Alice's associated token account for the native mint (NATIVE_MINT) already exists. If this ATA does not exist, transferring lamports to it will fail because the account does not exist on-chain.

    Suggestion: Ensure that Alice's ATA for the native mint exists before attempting the transfer. If it might not exist, add an instruction to create it:

    import { createAssociatedTokenAccountInstruction } from "@solana/spl-token";
    
    const ataAddress = state.alice.atas[splToken.NATIVE_MINT.toString()].address;
    const ataExists = await provider.connection.getAccountInfo(ataAddress);
    
    if (!ataExists) {
      tx.add(
        createAssociatedTokenAccountInstruction(
          state.alice.keypair.publicKey, // payer
          ataAddress, // ATA address
          state.alice.keypair.publicKey, // owner
          splToken.NATIVE_MINT // mint
        )
      );
    }

    Action: Include a check and create the ATA if it doesn't exist to prevent transaction failure.

  2. Unnecessary Inclusion of payer in Signers

    Issue: The sendAndConfirmTransaction function includes payer in the signers array along with state.alice.keypair. If payer is not required to sign any instructions in this transaction, including it is unnecessary and could cause confusion.

    Suggestion: Remove payer from the signers array if it's not needed:

    const txSignature = await sendAndConfirmTransaction(
      provider.connection,
      tx,
      [state.alice.keypair] // Removed 'payer'
    );

    Action: Verify if payer needs to sign the transaction. If not, exclude it from the signers to streamline the transaction.

By addressing these issues, the test will be more robust and conform to best practices, ensuring that it functions correctly in all scenarios.

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

Successfully merging this pull request may close these issues.

1 participant