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

Add Token Extensions as a Governance Plugin Program #95

Closed

Conversation

crypt0miester
Copy link
Contributor

@crypt0miester crypt0miester commented May 18, 2024

This pull request was created by https://app.gib.work/i/IAesrPp7/token2022-support-as-a-governance-plugin in an attempt to solve a bounty. Payment for the bounty is immediately sent to the contributor after merge.

The following changes are for the addressed issue in #93:

  1. Created Token-Voter Plugin Program
  2. Upgraded all programs to anchor v0.30.0
  3. Added tests for Token-Voter Plugin Program
  4. Small changes in the other plugin programs to make it anchor v0.30.0 compatible.

Regards,
miester.

@@ -197,7 +196,7 @@ async fn test_configure_registrar_with_invalid_spl_gov_program_id_error(
.unwrap();

// Assert
assert_anchor_err(err, anchor_lang::error::ErrorCode::ConstraintOwner);
assert_gateway_err(err, GatewayError::InvalidRealmForRegistrar);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this change but this test doesn't test what it says, It tests invalid Realm account but not its spl-governance program owner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason this has changed because anchor refuses to build if we use the previous assertion/constraint attached image

and I believe this is due to the registrar having the same name as the registrar account in here

we could either change the name of the registrar to registrar_account to be able to use the previous method and the anchor compiler does not complain.

programs/token-voter/Cargo.toml Outdated Show resolved Hide resolved
solana-program = "1.18.12"
# spl-governance = { version = "4.0.0", features = ["no-entrypoint"] }
# spl-transfer-hook-interface = { version = "0.6.3" }
spl-governance = { git = "https://github.com/crypt0miester/solana-program-library.git", branch = "gib-bounty-jlFb5", default-features = false, features = ["no-entrypoint"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes are required in spl-governance to support the plugin? Can you make a PR to SPL with the changes so we can reference a published version here please?

Copy link
Contributor Author

@crypt0miester crypt0miester Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do the changes and make PR to solana-program-library.

this was changed to use spl-governance in crates. code has been fixed to use it. since council_mint and community_mint does not have to be a token_2022 owned account.

programs/token-voter/Cargo.toml Outdated Show resolved Hide resolved
programs/token-voter/src/error.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,217 @@
/// A macro is exposed so that we can embed the program ID.
#[macro_export]
macro_rules! vote_weight_record {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check whether VoterWeightRecord and MaxVoterWeightRecord get exported in the program IDL?
As far as I can tell they are not but maybe I'm doing something wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are not exported in the IDL as an account (only Registrar and Voter are there). but the discriminator is included in the instructions and the types as well.

Would you like me to make it a regular state account instead of a macro?

programs/token-voter/src/tools/spl_token.rs Outdated Show resolved Hide resolved
}

/// Checks if the provided spl_token_program is spl token 2022
pub fn is_spl_token_2022(spl_token_program_id: &Pubkey) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think about any attack vectors atm but it would be safer to check for the token-2022 id instead of implying it by not being the token program

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only used once to verify that it is token-2022 account and if it is we check if the mint has extensions. this is done to create the spl-token-2022 account in here

programs/token-voter/src/tools/spl_token.rs Outdated Show resolved Hide resolved
programs/token-voter/src/tools/spl_token.rs Show resolved Hide resolved
@crypt0miester
Copy link
Contributor Author

closed in favor of #98

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