Skip to content

Issue when wallet_index is not 0 #3

Open

Description

@fniko

Upon trying to implemnt Jupiter Ultra API using this example standalone_script_examples/ultra-api/order-and-execute/main.py. It works from SOL to USDC (So11111111111111111111111111111111111111112 -> EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v), however when I try going back USDC -> SOL, I am getting the following error

    signed_transaction = VersionedTransaction(raw_transaction.message, signers)
TypeError: argument 'keypairs': failed to extract enum Signer ('KeypairWrapper | PresignerWrapper | NullSignerWrapper')
- variant KeypairWrapper (KeypairWrapper): TypeError: failed to extract field Signer::KeypairWrapper.0, caused by TypeError: 'Signature' object cannot be converted to 'Keypair'
- variant PresignerWrapper (PresignerWrapper): TypeError: failed to extract field Signer::PresignerWrapper.0, caused by TypeError: 'Signature' object cannot be converted to 'Presigner'
- variant NullSignerWrapper (NullSignerWrapper): TypeError: failed to extract field Signer::NullSignerWrapper.0, caused by TypeError: 'Signature' object cannot be converted to 'NullSigner'

I have discovered that the issue is linked to the index of my (signer) wallet. When it's the first one (wallet_index == 0), it works. When wallet_index > 0 (aka wallet_index == 1) this issue occurs.

List of signers than looks like this

[Signature(
    1111111111111111111111111111111111111111111111111111111111111111,
), Keypair(
    Keypair(
        Keypair {
            secret: SecretKey: [...],
            public: PublicKey(CompressedEdwardsY: [...]), EdwardsPoint{
                X: FieldElement51([...]),
                Y: FieldElement51([...]),
                Z: FieldElement51([...]),
                T: FieldElement51([...])
            }),
        },
    ),
)]

Can you please advise how to swap in the opposite direction? Thanks

I have checked also the example in standalone_script_examples/ultra-api/sell-everything-back-to-sol/main.py and the issue is the same.

Activity

  1. fniko commented on Oct 9, 2025

    @fniko
    Author

    I have solved the error using a different approach, maybe it will help

    def sign_transaction_v2(unsigned_transaction, wallet):
        # Signers are the first N account keys, where N == len(signatures)
        account_keys = unsigned_transaction.message.account_keys
        num_signers = len(unsigned_transaction.signatures)
    
        # Locate our wallet among all account keys
        wallet_account_index = account_keys.index(wallet.pubkey())
    
        # Ensure our wallet is actually a required signer
        if wallet_account_index >= num_signers:
            raise ValueError(
                f"Wallet pubkey is not in the required signers set "
                f"(wallet_index={wallet_account_index}, num_signers={num_signers})"
            )
    
        # Build signer list: NullSigner for everyone else, Keypair at our signer index
        signers = []
        for i in range(num_signers):
            if i == wallet_account_index:
                signers.append(wallet)
            else:
                # NullSigner needs the corresponding signer pubkey
                signers.append(NullSigner(account_keys[i]))
    
        signed_tx = VersionedTransaction(unsigned_transaction.message, signers)
        return base64.b64encode(bytes(signed_tx)).decode("utf-8")
  2. fniko commented on Oct 10, 2025

    @fniko
    Author
  3. cmoutafidis commented on Nov 25, 2025

    @cmoutafidis
    Member

    GM, I have made on the main branch on this script. Have a look if you can and let me know, I think this fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions