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

[feat]: Add #[idl_instruction] annotation to allow Shank programs to export shank'd IDL on-chain #42

Open
ngundotra opened this issue Oct 26, 2022 · 1 comment

Comments

@ngundotra
Copy link
Contributor

I think Shank would just need to feature flag the following code from anchor:

https://github.com/coral-xyz/anchor/blob/fa1249836e2b8a73d3cb9fb525634e789290f251/lang/syn/src/codegen/program/handlers.rs#L19

@ngundotra
Copy link
Contributor Author

ngundotra commented Oct 26, 2022

Ideally, shank would expose a macro that allowed me to redeploy my program with instructions to manage an on-chain IDL.

#[derive(ShankInstruction, ShankIdlDeploy)]
pub enum MyProgramInstruction {
  ...
}
// now if you fail to handle ShankIdlDeployParse -> fail in compiler
//  ShankIdlDeployParse

// now you add the following...
processor::parse_shank_idl_parse(program_id, &accounts, program_data)

// which then does the following
pub fn ....() {
let disc: ShankIdlInnerInstruction = parse(data)?;
match disc {
  ShankIdlInnerInstruction::CreateIdl =>
  shank::idl::create(program_id, &accounts, program_data)?
  ShankIdlInnerInstruction::CreateBuffer =>
  shank::idl::create_buffer(program_id, &accounts, program_data)?
  ShankIdlInnerInstruction::WriteIdl =>
  shank::idl::write(program_id, &accounts, program_data)?
  ShankIdlInnerInstruction::SetAuthority =>
  shank::idl::set_authority(program_id, &accounts, program_data)?
  ShankIdlInnerInstruction::SetBuffer =>
  shank::idl::set_buffer(program_id, &accounts, program_data)?
}

}

Anchor idl account is is derived via

const [key, bump] = PublicKey.findProgramAddressSync([], PROGRAM_ID);
PublicKey.createWithSeed(key, 'anchor:idl')

Here is the proof: part one and part two

@ngundotra ngundotra changed the title [feat]: Export PDA on-chain to write on-chain Anchor IDL [feat]: Add #[idlinstruction] annotation to allow Shank programs to export shank'd IDL on-chain Oct 29, 2022
@ngundotra ngundotra changed the title [feat]: Add #[idlinstruction] annotation to allow Shank programs to export shank'd IDL on-chain [feat]: Add #[idl_instruction] annotation to allow Shank programs to export shank'd IDL on-chain Oct 29, 2022
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

1 participant