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

Cannot find value in this scope error #84

Open
denimcodes opened this issue Jan 6, 2023 · 2 comments
Open

Cannot find value in this scope error #84

denimcodes opened this issue Jan 6, 2023 · 2 comments

Comments

@denimcodes
Copy link

denimcodes commented Jan 6, 2023

So I ran on this issue:
image

When I use new created account as authority in the same instruction, I get this error.

Here's the code:

class Pool(Account):
  bump: u8
  authority: Pubkey

@instruction
def init_pool(
  authority: Signer, 
  empty_pool: Empty[Pool], 
  token_mint: TokenMint, 
  token_vault: Empty[TokenAccount]
):
  pool = empty_pool.init(
    payer=authority,
    seeds=["pool", token_mint]
  )
  token_vault.init(
    payer=authority,
    mint=token_mint,
    authority=pool,
    associated=True
  )
@mcintyre94
Copy link
Contributor

mcintyre94 commented Jan 6, 2023

Hey, thanks for reporting this! I think this is a dupe of #39 which is unresolved, and should have the same (a bit hacky) workaround:

@instruction
def init_pool(
    authority: Signer,
    pool: Empty[Pool],
    token_mint: TokenMint,
    token_vault: Empty[TokenAccount]
):
    pool = pool.init(
        payer=authority,
        seeds=["pool", token_mint]
    )
    token_vault.init(
        payer=authority,
        mint=token_mint,
        authority=pool,
        associated=True
    )

Here I've renamed empty_pool to pool, and initialise it to the same variable.

The way we do init calls sequentially is a bit confusing and doesn't quite map to what Anchor is doing. There's more detail in my comments on #39 but basically we can't pass anything created in the function (in your case the pool variable) into an init call.

But you also can't use authority = empty_pool, because the Seahorse compiler won't let you use an empty account as an authority that might not have been initialised

So the workaround makes both Anchor and Seahorse happy: Anchor knows what pool is because it's an argument to the function, Seahorse can see that you're initialising it before using it as authority.

@denimcodes
Copy link
Author

Got it. The workaround is working as expected. Thanks.

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