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

USDC deposits do not work: wrong close_account call and UnboundLocalError: local variable 'ata_pubkey' referenced before assignment #209

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

akalmykov
Copy link
Contributor

@akalmykov akalmykov commented Dec 8, 2024

Comparing TS SDK deposit with Python SDK deposits reveals a problem with close_account call when trying to deposit something different from WSOL, e.g. USDC deposit.

First, this line uses ata_pubkey that might not be initialized:

account=ata_pubkey,

which results in:

UnboundLocalError: local variable 'ata_pubkey' referenced before assignment

The reason is that only get initilized here

ixs, ata_pubkey = await self.get_wrapped_sol_account_creation_ixs(amount)

Instead of ata_pubkey , user_token_account should be used as it happens in TS SDK.

Second, similar to TS sdk we need to check create_WSOL_token_account before adding close instruction to the transaction:

        if create_WSOL_token_account:
            close_account_params = CloseAccountParams(
                program_id=TOKEN_PROGRAM_ID,
                account=user_token_account,
                dest=signer_authority,
                owner=signer_authority,
            )
            close_account_ix = close_account(close_account_params)
            instructions.append(close_account_ix)

@SinaKhalili
Copy link
Contributor

Looks good, thanks for catching this

@SinaKhalili SinaKhalili merged commit 69e8530 into drift-labs:master Dec 10, 2024
1 of 2 checks passed
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.

2 participants