Skip to content

check native src tx cost#67

Draft
SevenSwen wants to merge 2 commits intomainfrom
test/check_create_native_src
Draft

check native src tx cost#67
SevenSwen wants to merge 2 commits intomainfrom
test/check_create_native_src

Conversation

@SevenSwen
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

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