From f1571f5fea3a3bda46bd848e8e0d66ce4e87b19b Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 7 Nov 2023 10:34:54 +0000 Subject: [PATCH] rustfmt: format imports --- .../program-test/tests/spl_token_create.rs | 5 +- binary-option/program/src/entrypoint.rs | 7 +- binary-option/program/src/error.rs | 4 +- binary-option/program/src/instruction.rs | 13 +- binary-option/program/src/processor.rs | 48 ++--- binary-option/program/src/state.rs | 13 +- binary-oracle-pair/program/src/entrypoint.rs | 10 +- binary-oracle-pair/program/src/error.rs | 14 +- binary-oracle-pair/program/src/instruction.rs | 16 +- binary-oracle-pair/program/src/processor.rs | 39 ++-- binary-oracle-pair/program/src/state.rs | 6 +- binary-oracle-pair/program/tests/tests.rs | 20 ++- examples/rust/custom-heap/src/entrypoint.rs | 12 +- feature-proposal/program/src/instruction.rs | 20 ++- feature-proposal/program/src/processor.rs | 28 +-- feature-proposal/program/src/state.rs | 14 +- governance/addin-api/src/max_voter_weight.rs | 8 +- governance/addin-api/src/voter_weight.rs | 8 +- .../addin-mock/program/src/entrypoint.rs | 10 +- governance/addin-mock/program/src/error.rs | 14 +- .../addin-mock/program/src/instruction.rs | 16 +- .../addin-mock/program/src/processor.rs | 32 ++-- governance/chat/program/src/entrypoint.rs | 10 +- governance/chat/program/src/error.rs | 14 +- governance/chat/program/src/instruction.rs | 17 +- governance/chat/program/src/processor.rs | 47 ++--- governance/chat/program/src/state.rs | 12 +- .../program/tests/process_post_message.rs | 10 +- .../program/tests/program_test/cookies.rs | 7 +- .../chat/program/tests/program_test/mod.rs | 58 +++--- .../program/src/addins/max_voter_weight.rs | 15 +- governance/program/src/addins/voter_weight.rs | 15 +- governance/program/src/entrypoint.rs | 10 +- governance/program/src/error.rs | 14 +- governance/program/src/instruction.rs | 60 ++++--- governance/program/src/processor/mod.rs | 72 ++++---- .../process_add_required_signatory.rs | 31 ++-- .../src/processor/process_add_signatory.rs | 37 ++-- .../src/processor/process_cancel_proposal.rs | 25 +-- .../src/processor/process_cast_vote.rs | 47 ++--- .../processor/process_complete_proposal.rs | 23 +-- .../processor/process_create_governance.rs | 35 ++-- .../process_create_mint_governance.rs | 45 ++--- .../process_create_native_treasury.rs | 27 +-- .../process_create_program_governance.rs | 44 ++--- .../src/processor/process_create_proposal.rs | 49 ++--- .../src/processor/process_create_realm.rs | 41 ++--- .../process_create_token_governance.rs | 43 ++--- .../process_create_token_owner_record.rs | 35 ++-- .../process_deposit_governing_tokens.rs | 43 ++--- .../processor/process_execute_transaction.rs | 33 ++-- .../src/processor/process_finalize_vote.rs | 28 +-- .../process_flag_transaction_error.rs | 27 +-- .../processor/process_insert_transaction.rs | 40 ++--- .../process_refund_proposal_deposit.rs | 21 +-- .../src/processor/process_relinquish_vote.rs | 37 ++-- .../process_remove_required_signatory.rs | 24 +-- .../processor/process_remove_transaction.rs | 22 +-- .../process_revoke_governing_tokens.rs | 27 +-- .../process_set_governance_config.rs | 21 ++- .../process_set_governance_delegate.rs | 13 +- .../processor/process_set_realm_authority.rs | 23 +-- .../src/processor/process_set_realm_config.rs | 35 ++-- .../processor/process_sign_off_proposal.rs | 32 ++-- .../process_update_program_metadata.rs | 31 ++-- .../process_withdraw_governing_tokens.rs | 29 +-- governance/program/src/state/governance.rs | 46 +++-- governance/program/src/state/legacy.rs | 28 +-- .../program/src/state/native_treasury.rs | 8 +- .../program/src/state/program_metadata.rs | 15 +- governance/program/src/state/proposal.rs | 84 +++++---- .../program/src/state/proposal_deposit.rs | 15 +- .../program/src/state/proposal_transaction.rs | 39 ++-- governance/program/src/state/realm.rs | 57 +++--- governance/program/src/state/realm_config.rs | 41 +++-- .../program/src/state/required_signatory.rs | 14 +- .../program/src/state/signatory_record.rs | 24 +-- .../program/src/state/token_owner_record.rs | 50 +++--- governance/program/src/state/vote_record.rs | 41 ++--- .../src/tools/bpf_loader_upgradeable.rs | 20 +-- governance/program/src/tools/pack.rs | 6 +- governance/program/src/tools/spl_token.rs | 37 ++-- .../program/tests/migrate_legacy_accounts.rs | 12 +- .../tests/process_add_required_signatory.rs | 18 +- .../program/tests/process_add_signatory.rs | 20 +-- .../program/tests/process_cancel_proposal.rs | 9 +- governance/program/tests/process_cast_vote.rs | 22 +-- .../tests/process_complete_proposal.rs | 10 +- .../tests/process_create_governance.rs | 15 +- .../tests/process_create_mint_governance.rs | 15 +- .../process_create_program_governance.rs | 17 +- .../program/tests/process_create_proposal.rs | 20 ++- .../program/tests/process_create_realm.rs | 9 +- .../tests/process_create_token_governance.rs | 16 +- .../process_create_token_owner_record.rs | 5 +- .../tests/process_deposit_governing_tokens.rs | 22 +-- .../tests/process_execute_transaction.rs | 23 +-- .../program/tests/process_finalize_vote.rs | 13 +- .../tests/process_flag_transaction_error.rs | 13 +- .../tests/process_insert_transaction.rs | 5 +- .../tests/process_refund_proposal_deposit.rs | 6 +- .../program/tests/process_relinquish_vote.rs | 23 +-- .../process_remove_required_signatory.rs | 17 +- .../tests/process_remove_transaction.rs | 5 +- .../tests/process_revoke_governing_tokens.rs | 21 ++- .../tests/process_set_governance_config.rs | 17 +- .../tests/process_set_governance_delegate.rs | 11 +- .../tests/process_set_realm_authority.rs | 10 +- .../program/tests/process_set_realm_config.rs | 16 +- .../tests/process_sign_off_proposal.rs | 15 +- .../process_withdraw_governing_tokens.rs | 26 +-- .../program/tests/program_test/cookies.rs | 27 +-- .../program/tests/program_test/legacy.rs | 8 +- governance/program/tests/program_test/mod.rs | 168 +++++++++--------- .../tests/setup_realm_with_all_addins.rs | 7 +- ...setup_realm_with_max_voter_weight_addin.rs | 7 +- .../setup_realm_with_voter_weight_addin.rs | 6 +- .../use_proposals_with_multiple_options.rs | 17 +- .../tests/use_realm_with_all_addins.rs | 7 +- .../use_realm_with_max_voter_weight_addin.rs | 7 +- .../use_realm_with_voter_weight_addin.rs | 17 +- governance/program/tests/use_veto_vote.rs | 25 ++- governance/test-sdk/src/addins.rs | 9 +- governance/test-sdk/src/cookies.rs | 3 +- governance/test-sdk/src/lib.rs | 42 +++-- governance/test-sdk/src/tools.rs | 9 +- governance/tools/src/account.rs | 32 ++-- governance/tools/src/error.rs | 14 +- .../src/concurrent_merkle_tree.rs | 19 +- libraries/concurrent-merkle-tree/src/hash.rs | 6 +- .../concurrent-merkle-tree/tests/tests.rs | 15 +- libraries/math/src/error.rs | 3 +- libraries/math/src/precise_number.rs | 3 +- libraries/math/src/processor.rs | 4 +- libraries/merkle-tree-reference/src/lib.rs | 9 +- libraries/pod/src/optional_keys.rs | 16 +- libraries/pod/src/primitives.rs | 6 +- managed-token/program/src/accounts.rs | 12 +- managed-token/program/src/instruction.rs | 21 +-- managed-token/program/src/lib.rs | 22 ++- managed-token/program/tests/test.rs | 34 ++-- memo/program/src/processor.rs | 20 ++- memo/program/tests/functional.rs | 20 ++- name-service/program/src/entrypoint.rs | 3 +- name-service/program/src/processor.rs | 3 +- name-service/program/tests/functional.rs | 33 ++-- record/program/src/error.rs | 8 +- record/program/src/instruction.rs | 16 +- record/program/src/state.rs | 3 +- rustfmt.toml | 4 +- shared-memory/program/src/lib.rs | 22 ++- shared-memory/program/tests/shared-memory.rs | 17 +- single-pool/cli/src/config.rs | 3 +- single-pool/cli/src/main.rs | 3 +- single-pool/cli/src/quarantine.rs | 23 +-- stake-pool/cli/src/main.rs | 12 +- stake-pool/cli/src/output.rs | 3 +- stateless-asks/program/src/entrypoint.rs | 7 +- stateless-asks/program/src/error.rs | 4 +- stateless-asks/program/src/processor.rs | 3 +- .../program/src/validation_utils.rs | 21 +-- .../flash_loan_receiver/src/processor.rs | 19 +- token-lending/program/src/entrypoint.rs | 10 +- token-lending/program/src/error.rs | 8 +- token-lending/program/src/instruction.rs | 24 +-- token-lending/program/src/math/decimal.rs | 14 +- token-lending/program/src/math/mod.rs | 4 +- token-lending/program/src/math/rate.rs | 14 +- token-lending/program/src/processor.rs | 56 +++--- .../program/src/state/last_update.rs | 8 +- .../program/src/state/lending_market.rs | 16 +- token-lending/program/src/state/mod.rs | 18 +- token-lending/program/src/state/obligation.rs | 40 ++--- token-lending/program/src/state/reserve.rs | 46 ++--- .../tests/borrow_obligation_liquidity.rs | 30 ++-- .../tests/deposit_obligation_collateral.rs | 22 +-- .../tests/deposit_reserve_liquidity.rs | 8 +- token-lending/program/tests/flash_loan.rs | 24 +-- .../tests/helpers/flash_loan_receiver.rs | 22 +-- token-lending/program/tests/helpers/mod.rs | 52 +++--- .../program/tests/init_lending_market.rs | 20 ++- .../program/tests/init_obligation.rs | 20 ++- token-lending/program/tests/init_reserve.rs | 26 +-- .../program/tests/liquidate_obligation.rs | 24 +-- .../program/tests/modify_reserve_config.rs | 32 ++-- .../program/tests/obligation_end_to_end.rs | 36 ++-- .../tests/redeem_reserve_collateral.rs | 22 +-- .../program/tests/refresh_obligation.rs | 26 +-- .../program/tests/refresh_reserve.rs | 24 +-- .../tests/repay_obligation_liquidity.rs | 24 +-- .../program/tests/set_lending_market_owner.rs | 28 +-- .../tests/withdraw_obligation_collateral.rs | 28 +-- token-metadata/interface/src/instruction.rs | 8 +- token-metadata/interface/src/lib.rs | 3 +- token-metadata/interface/src/state.rs | 5 +- .../program/fuzz/src/native_processor.rs | 11 +- token-swap/program/fuzz/src/native_token.rs | 10 +- .../program/fuzz/src/native_token_swap.rs | 28 +-- token-swap/program/src/constraints.rs | 27 +-- token-swap/program/src/curve/base.rs | 40 ++--- token-swap/program/src/curve/calculator.rs | 7 +- .../program/src/curve/constant_price.rs | 18 +- .../program/src/curve/constant_product.rs | 20 ++- token-swap/program/src/curve/fees.rs | 14 +- token-swap/program/src/curve/offset.rs | 20 ++- token-swap/program/src/entrypoint.rs | 10 +- token-swap/program/src/error.rs | 14 +- token-swap/program/src/instruction.rs | 32 ++-- token-swap/program/src/processor.rs | 130 +++++++------- token-swap/program/src/state.rs | 41 +++-- token/cli/src/config.rs | 50 +++--- token/cli/src/main.rs | 153 ++++++++-------- token/cli/src/output.rs | 28 +-- token/cli/src/sort.rs | 26 +-- token/client/src/token.rs | 6 +- .../ciphertext_extraction.rs | 1 - .../confidential_transfer/instruction.rs | 11 +- .../confidential_transfer/processor.rs | 12 +- .../confidential_transfer_fee/instruction.rs | 11 +- .../confidential_transfer_fee/processor.rs | 7 +- .../src/extension/cpi_guard/instruction.rs | 5 +- .../src/extension/cpi_guard/mod.rs | 5 +- .../default_account_state/instruction.rs | 5 +- .../extension/default_account_state/mod.rs | 5 +- .../extension/group_pointer/instruction.rs | 5 +- .../src/extension/group_pointer/mod.rs | 5 +- .../src/extension/immutable_owner.rs | 5 +- .../interest_bearing_mint/instruction.rs | 5 +- .../extension/interest_bearing_mint/mod.rs | 5 +- .../extension/memo_transfer/instruction.rs | 5 +- .../src/extension/memo_transfer/mod.rs | 5 +- .../extension/metadata_pointer/instruction.rs | 5 +- .../src/extension/metadata_pointer/mod.rs | 5 +- .../src/extension/mint_close_authority.rs | 5 +- token/program-2022/src/extension/mod.rs | 5 +- .../src/extension/non_transferable.rs | 5 +- .../src/extension/permanent_delegate.rs | 5 +- .../src/extension/transfer_fee/instruction.rs | 11 +- .../src/extension/transfer_fee/mod.rs | 5 +- .../extension/transfer_hook/instruction.rs | 5 +- .../src/extension/transfer_hook/mod.rs | 5 +- token/program-2022/src/instruction.rs | 13 +- token/program-2022/src/lib.rs | 3 +- token/program-2022/src/state.rs | 3 +- token/program/src/entrypoint.rs | 10 +- token/program/src/error.rs | 14 +- token/program/src/instruction.rs | 19 +- token/program/src/native_mint.rs | 3 +- token/program/src/processor.rs | 68 +++---- token/program/src/state.rs | 18 +- utils/cgen/src/main.rs | 3 +- 251 files changed, 2685 insertions(+), 2513 deletions(-) diff --git a/associated-token-account/program-test/tests/spl_token_create.rs b/associated-token-account/program-test/tests/spl_token_create.rs index ec476e61bb3..32f08d03b6d 100644 --- a/associated-token-account/program-test/tests/spl_token_create.rs +++ b/associated-token-account/program-test/tests/spl_token_create.rs @@ -3,6 +3,8 @@ mod program_test; +#[allow(deprecated)] +use spl_associated_token_account::create_associated_token_account as deprecated_create_associated_token_account; use { program_test::program_test, solana_program::pubkey::Pubkey, @@ -14,9 +16,6 @@ use { spl_token::state::Account, }; -#[allow(deprecated)] -use spl_associated_token_account::create_associated_token_account as deprecated_create_associated_token_account; - #[tokio::test] async fn success_create() { let wallet_address = Pubkey::new_unique(); diff --git a/binary-option/program/src/entrypoint.rs b/binary-option/program/src/entrypoint.rs index 57a98a463b8..cbf8ed562f9 100644 --- a/binary-option/program/src/entrypoint.rs +++ b/binary-option/program/src/entrypoint.rs @@ -1,8 +1,9 @@ #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; - -use crate::processor::Processor; +use { + crate::processor::Processor, + solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, +}; solana_program::entrypoint!(process_instruction); fn process_instruction( diff --git a/binary-option/program/src/error.rs b/binary-option/program/src/error.rs index c04e0d8b543..8c9ccdda264 100644 --- a/binary-option/program/src/error.rs +++ b/binary-option/program/src/error.rs @@ -1,6 +1,4 @@ -use thiserror::Error; - -use solana_program::program_error::ProgramError; +use {solana_program::program_error::ProgramError, thiserror::Error}; #[derive(Error, Debug, Copy, Clone)] pub enum BinaryOptionError { diff --git a/binary-option/program/src/instruction.rs b/binary-option/program/src/instruction.rs index e1a7dd814fd..8596c264e78 100644 --- a/binary-option/program/src/instruction.rs +++ b/binary-option/program/src/instruction.rs @@ -1,11 +1,12 @@ -use solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - sysvar, +use { + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + sysvar, + }, }; -use borsh::{BorshDeserialize, BorshSerialize}; - #[repr(C)] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Clone)] pub struct InitializeBinaryOptionArgs { diff --git a/binary-option/program/src/processor.rs b/binary-option/program/src/processor.rs index 64dc0a25dea..c9f9c82b316 100644 --- a/binary-option/program/src/processor.rs +++ b/binary-option/program/src/processor.rs @@ -1,28 +1,30 @@ -use crate::{ - error::BinaryOptionError, - instruction::BinaryOptionInstruction, - spl_utils::{ - spl_approve, spl_burn, spl_burn_signed, spl_initialize, spl_mint_initialize, spl_mint_to, - spl_set_authority, spl_token_transfer, spl_token_transfer_signed, +use { + crate::{ + error::BinaryOptionError, + instruction::BinaryOptionInstruction, + spl_utils::{ + spl_approve, spl_burn, spl_burn_signed, spl_initialize, spl_mint_initialize, + spl_mint_to, spl_set_authority, spl_token_transfer, spl_token_transfer_signed, + }, + state::BinaryOption, + system_utils::{create_new_account, create_or_allocate_account_raw}, + validation_utils::{ + assert_initialized, assert_keys_equal, assert_keys_unequal, assert_owned_by, + }, }, - state::BinaryOption, - system_utils::{create_new_account, create_or_allocate_account_raw}, - validation_utils::{ - assert_initialized, assert_keys_equal, assert_keys_unequal, assert_owned_by, + borsh::BorshDeserialize, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, + program_pack::Pack, + pubkey::Pubkey, + }, + spl_token::{ + instruction::AuthorityType, + state::{Account, Mint}, }, -}; -use borsh::BorshDeserialize; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - program_pack::Pack, - pubkey::Pubkey, -}; -use spl_token::{ - instruction::AuthorityType, - state::{Account, Mint}, }; pub struct Processor; diff --git a/binary-option/program/src/state.rs b/binary-option/program/src/state.rs index 4f139112475..b04cc0223b0 100644 --- a/binary-option/program/src/state.rs +++ b/binary-option/program/src/state.rs @@ -1,11 +1,12 @@ -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, - pubkey::Pubkey, +use { + crate::error::BinaryOptionError, + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, + pubkey::Pubkey, + }, }; -use crate::error::BinaryOptionError; -use borsh::{BorshDeserialize, BorshSerialize}; - #[repr(C)] #[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] pub struct BinaryOption { diff --git a/binary-oracle-pair/program/src/entrypoint.rs b/binary-oracle-pair/program/src/entrypoint.rs index 693aed651b8..b6c32a48e65 100644 --- a/binary-oracle-pair/program/src/entrypoint.rs +++ b/binary-oracle-pair/program/src/entrypoint.rs @@ -2,10 +2,12 @@ #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use crate::{error::PoolError, processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::PoolError, processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/binary-oracle-pair/program/src/error.rs b/binary-oracle-pair/program/src/error.rs index 17884848bc4..9da5a15d52b 100644 --- a/binary-oracle-pair/program/src/error.rs +++ b/binary-oracle-pair/program/src/error.rs @@ -1,11 +1,15 @@ //! Error types -use num_derive::FromPrimitive; -use num_traits::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, msg, program_error::PrintProgramError, program_error::ProgramError, +use { + num_derive::FromPrimitive, + num_traits::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the Binary Oracle Pair program. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/binary-oracle-pair/program/src/instruction.rs b/binary-oracle-pair/program/src/instruction.rs index 67c72881c13..60c6c2c739d 100644 --- a/binary-oracle-pair/program/src/instruction.rs +++ b/binary-oracle-pair/program/src/instruction.rs @@ -1,12 +1,14 @@ //! Instruction types -use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::{ - clock::Slot, - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - pubkey::Pubkey, - sysvar, +use { + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::{ + clock::Slot, + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + pubkey::Pubkey, + sysvar, + }, }; /// Initialize arguments for pool diff --git a/binary-oracle-pair/program/src/processor.rs b/binary-oracle-pair/program/src/processor.rs index 1a2ad652414..bec3d560fe0 100644 --- a/binary-oracle-pair/program/src/processor.rs +++ b/binary-oracle-pair/program/src/processor.rs @@ -1,25 +1,26 @@ //! Program state processor -use crate::{ - error::PoolError, - instruction::PoolInstruction, - state::{Decision, Pool, POOL_VERSION}, +use { + crate::{ + error::PoolError, + instruction::PoolInstruction, + state::{Decision, Pool, POOL_VERSION}, + }, + borsh::BorshDeserialize, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::{Clock, Slot}, + entrypoint::ProgramResult, + msg, + program::{invoke, invoke_signed}, + program_error::ProgramError, + program_pack::{IsInitialized, Pack}, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_token::state::{Account, Mint}, }; -use borsh::BorshDeserialize; -use solana_program::{ - account_info::next_account_info, - account_info::AccountInfo, - clock::{Clock, Slot}, - entrypoint::ProgramResult, - msg, - program::{invoke, invoke_signed}, - program_error::ProgramError, - program_pack::{IsInitialized, Pack}, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_token::state::{Account, Mint}; /// Program state handler. pub struct Processor {} diff --git a/binary-oracle-pair/program/src/state.rs b/binary-oracle-pair/program/src/state.rs index 9b8438f650e..c17910c583f 100644 --- a/binary-oracle-pair/program/src/state.rs +++ b/binary-oracle-pair/program/src/state.rs @@ -1,7 +1,9 @@ //! State transition types -use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::pubkey::Pubkey; +use { + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::pubkey::Pubkey, +}; /// Uninitialized version value, all instances are at least version 1 pub const UNINITIALIZED_VERSION: u8 = 0; diff --git a/binary-oracle-pair/program/tests/tests.rs b/binary-oracle-pair/program/tests/tests.rs index ff00df002c5..e6c913e5968 100644 --- a/binary-oracle-pair/program/tests/tests.rs +++ b/binary-oracle-pair/program/tests/tests.rs @@ -1,15 +1,17 @@ #![cfg(feature = "test-sbf")] -use borsh::de::BorshDeserialize; -use solana_program::{hash::Hash, program_pack::Pack, pubkey::Pubkey, system_instruction}; -use solana_program_test::*; -use solana_sdk::{ - account::Account, - signature::{Keypair, Signer}, - transaction::Transaction, - transport::TransportError, +use { + borsh::de::BorshDeserialize, + solana_program::{hash::Hash, program_pack::Pack, pubkey::Pubkey, system_instruction}, + solana_program_test::*, + solana_sdk::{ + account::Account, + signature::{Keypair, Signer}, + transaction::Transaction, + transport::TransportError, + }, + spl_binary_oracle_pair::*, }; -use spl_binary_oracle_pair::*; pub fn program_test() -> ProgramTest { ProgramTest::new( diff --git a/examples/rust/custom-heap/src/entrypoint.rs b/examples/rust/custom-heap/src/entrypoint.rs index 9f398acc114..ba448c3f579 100644 --- a/examples/rust/custom-heap/src/entrypoint.rs +++ b/examples/rust/custom-heap/src/entrypoint.rs @@ -2,12 +2,14 @@ #![cfg(not(feature = "no-entrypoint"))] -use solana_program::{ - account_info::AccountInfo, - entrypoint::{ProgramResult, HEAP_LENGTH, HEAP_START_ADDRESS}, - pubkey::Pubkey, +use { + solana_program::{ + account_info::AccountInfo, + entrypoint::{ProgramResult, HEAP_LENGTH, HEAP_START_ADDRESS}, + pubkey::Pubkey, + }, + std::{alloc::Layout, mem::size_of, ptr::null_mut, usize}, }; -use std::{alloc::Layout, mem::size_of, ptr::null_mut, usize}; /// Developers can implement their own heap by defining their own /// `#[global_allocator]`. The following implements a dummy for test purposes diff --git a/feature-proposal/program/src/instruction.rs b/feature-proposal/program/src/instruction.rs index b73c0c8c575..c00e5bfbfc5 100644 --- a/feature-proposal/program/src/instruction.rs +++ b/feature-proposal/program/src/instruction.rs @@ -1,14 +1,16 @@ //! Program instructions -use crate::{state::AcceptanceCriteria, *}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - msg, - program_error::ProgramError, - program_pack::{Pack, Sealed}, - pubkey::Pubkey, - sysvar, +use { + crate::{state::AcceptanceCriteria, *}, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + instruction::{AccountMeta, Instruction}, + msg, + program_error::ProgramError, + program_pack::{Pack, Sealed}, + pubkey::Pubkey, + sysvar, + }, }; /// Instructions supported by the Feature Proposal program diff --git a/feature-proposal/program/src/processor.rs b/feature-proposal/program/src/processor.rs index ec188953e54..3ba486978e2 100644 --- a/feature-proposal/program/src/processor.rs +++ b/feature-proposal/program/src/processor.rs @@ -1,18 +1,20 @@ //! Program state processor -use crate::{instruction::*, state::*, *}; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - feature::{self, Feature}, - msg, - program::{invoke, invoke_signed}, - program_error::ProgramError, - pubkey::Pubkey, - rent::Rent, - system_instruction, - sysvar::Sysvar, +use { + crate::{instruction::*, state::*, *}, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + feature::{self, Feature}, + msg, + program::{invoke, invoke_signed}, + program_error::ProgramError, + pubkey::Pubkey, + rent::Rent, + system_instruction, + sysvar::Sysvar, + }, }; /// Instruction processor diff --git a/feature-proposal/program/src/state.rs b/feature-proposal/program/src/state.rs index 559d0b12488..a5bde3fdaa3 100644 --- a/feature-proposal/program/src/state.rs +++ b/feature-proposal/program/src/state.rs @@ -1,10 +1,12 @@ //! Program state -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - clock::UnixTimestamp, - msg, - program_error::ProgramError, - program_pack::{Pack, Sealed}, +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + clock::UnixTimestamp, + msg, + program_error::ProgramError, + program_pack::{Pack, Sealed}, + }, }; /// Criteria for accepting a feature proposal diff --git a/governance/addin-api/src/max_voter_weight.rs b/governance/addin-api/src/max_voter_weight.rs index 5e14fa6ba32..205b84a12b7 100644 --- a/governance/addin-api/src/max_voter_weight.rs +++ b/governance/addin-api/src/max_voter_weight.rs @@ -1,8 +1,10 @@ //! MaxVoterWeight Addin interface -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{clock::Slot, program_pack::IsInitialized, pubkey::Pubkey}; -use spl_governance_tools::account::AccountMaxSize; +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{clock::Slot, program_pack::IsInitialized, pubkey::Pubkey}, + spl_governance_tools::account::AccountMaxSize, +}; /// MaxVoterWeightRecord account /// The account is used as an api interface to provide max voting power to the governance program from external addin contracts diff --git a/governance/addin-api/src/voter_weight.rs b/governance/addin-api/src/voter_weight.rs index ecadafce84b..ada1a10edab 100644 --- a/governance/addin-api/src/voter_weight.rs +++ b/governance/addin-api/src/voter_weight.rs @@ -1,8 +1,10 @@ //! VoterWeight Addin interface -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{clock::Slot, program_pack::IsInitialized, pubkey::Pubkey}; -use spl_governance_tools::account::AccountMaxSize; +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{clock::Slot, program_pack::IsInitialized, pubkey::Pubkey}, + spl_governance_tools::account::AccountMaxSize, +}; /// The governance action VoterWeight is evaluated for #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/addin-mock/program/src/entrypoint.rs b/governance/addin-mock/program/src/entrypoint.rs index befeaa5c0a4..692954a81c9 100644 --- a/governance/addin-mock/program/src/entrypoint.rs +++ b/governance/addin-mock/program/src/entrypoint.rs @@ -1,10 +1,12 @@ //! Program entrypoint #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use crate::{error::VoterWeightAddinError, processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::VoterWeightAddinError, processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/governance/addin-mock/program/src/error.rs b/governance/addin-mock/program/src/error.rs index 0d17cf04aeb..0ce4bfd8643 100644 --- a/governance/addin-mock/program/src/error.rs +++ b/governance/addin-mock/program/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the VoterWeightAddin program #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/governance/addin-mock/program/src/instruction.rs b/governance/addin-mock/program/src/instruction.rs index b31b7a0fb72..5bd232268a0 100644 --- a/governance/addin-mock/program/src/instruction.rs +++ b/governance/addin-mock/program/src/instruction.rs @@ -1,13 +1,15 @@ //! Program instructions -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - clock::Slot, - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + clock::Slot, + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + system_program, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, }; -use spl_governance_addin_api::voter_weight::VoterWeightAction; /// Instructions supported by the VoterWeight addin program /// This program is a mock program used by spl-governance for testing and not real addin diff --git a/governance/addin-mock/program/src/processor.rs b/governance/addin-mock/program/src/processor.rs index f3c59d4e5ab..78856294e8c 100644 --- a/governance/addin-mock/program/src/processor.rs +++ b/governance/addin-mock/program/src/processor.rs @@ -1,22 +1,22 @@ //! Program processor -use borsh::BorshDeserialize; - -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Slot, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - pubkey::Pubkey, -}; -use spl_governance_addin_api::{ - max_voter_weight::MaxVoterWeightRecord, - voter_weight::{VoterWeightAction, VoterWeightRecord}, +use { + crate::instruction::VoterWeightAddinInstruction, + borsh::BorshDeserialize, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Slot, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, + pubkey::Pubkey, + }, + spl_governance_addin_api::{ + max_voter_weight::MaxVoterWeightRecord, + voter_weight::{VoterWeightAction, VoterWeightRecord}, + }, + spl_governance_tools::account::create_and_serialize_account, }; -use spl_governance_tools::account::create_and_serialize_account; - -use crate::instruction::VoterWeightAddinInstruction; /// Processes an instruction pub fn process_instruction( diff --git a/governance/chat/program/src/entrypoint.rs b/governance/chat/program/src/entrypoint.rs index 5dea31c8df6..c7f4fa52a48 100644 --- a/governance/chat/program/src/entrypoint.rs +++ b/governance/chat/program/src/entrypoint.rs @@ -1,10 +1,12 @@ //! Program entrypoint #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use crate::{error::GovernanceChatError, processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::GovernanceChatError, processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/governance/chat/program/src/error.rs b/governance/chat/program/src/error.rs index 74e8dc10feb..8ce588df8fb 100644 --- a/governance/chat/program/src/error.rs +++ b/governance/chat/program/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the GovernanceChat program #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/governance/chat/program/src/instruction.rs b/governance/chat/program/src/instruction.rs index e0391231f8c..b062cc45dc8 100644 --- a/governance/chat/program/src/instruction.rs +++ b/governance/chat/program/src/instruction.rs @@ -1,14 +1,15 @@ //! Program instructions -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, +use { + crate::state::MessageBody, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + system_program, + }, + spl_governance::instruction::with_realm_config_accounts, }; -use spl_governance::instruction::with_realm_config_accounts; - -use crate::state::MessageBody; /// Instructions supported by the GovernanceChat program #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/chat/program/src/processor.rs b/governance/chat/program/src/processor.rs index 208d4ea175e..a8535167e71 100644 --- a/governance/chat/program/src/processor.rs +++ b/governance/chat/program/src/processor.rs @@ -1,28 +1,31 @@ //! Program processor -use crate::{ - error::GovernanceChatError, - instruction::GovernanceChatInstruction, - state::{assert_is_valid_chat_message, ChatMessage, GovernanceChatAccountType, MessageBody}, +use { + crate::{ + error::GovernanceChatError, + instruction::GovernanceChatInstruction, + state::{ + assert_is_valid_chat_message, ChatMessage, GovernanceChatAccountType, MessageBody, + }, + }, + borsh::BorshDeserialize, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, + pubkey::Pubkey, + sysvar::Sysvar, + }, + spl_governance::state::{ + governance::get_governance_data_for_realm, proposal::get_proposal_data_for_governance, + realm::get_realm_data, realm_config::get_realm_config_data_for_realm, + token_owner_record::get_token_owner_record_data_for_realm, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, + spl_governance_tools::account::create_and_serialize_account, }; -use borsh::BorshDeserialize; - -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - pubkey::Pubkey, - sysvar::Sysvar, -}; -use spl_governance::state::{ - governance::get_governance_data_for_realm, proposal::get_proposal_data_for_governance, - realm::get_realm_data, realm_config::get_realm_config_data_for_realm, - token_owner_record::get_token_owner_record_data_for_realm, -}; -use spl_governance_addin_api::voter_weight::VoterWeightAction; -use spl_governance_tools::account::create_and_serialize_account; /// Processes an instruction pub fn process_instruction( diff --git a/governance/chat/program/src/state.rs b/governance/chat/program/src/state.rs index 957465f9517..92fcd3f9202 100644 --- a/governance/chat/program/src/state.rs +++ b/governance/chat/program/src/state.rs @@ -1,12 +1,14 @@ //! Program state -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, clock::UnixTimestamp, program_error::ProgramError, pubkey::Pubkey, +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, clock::UnixTimestamp, program_error::ProgramError, + pubkey::Pubkey, + }, + spl_governance_tools::account::{assert_is_valid_account_of_type, AccountMaxSize}, }; -use spl_governance_tools::account::{assert_is_valid_account_of_type, AccountMaxSize}; - /// Defines all GovernanceChat accounts types #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] pub enum GovernanceChatAccountType { diff --git a/governance/chat/program/tests/process_post_message.rs b/governance/chat/program/tests/process_post_message.rs index 3ae5df5db55..2bf57fa986b 100644 --- a/governance/chat/program/tests/process_post_message.rs +++ b/governance/chat/program/tests/process_post_message.rs @@ -1,10 +1,10 @@ #![cfg(feature = "test-sbf")] -use program_test::GovernanceChatProgramTest; -use solana_program_test::tokio; -use solana_sdk::signature::Keypair; -use spl_governance::error::GovernanceError; -use spl_governance_chat::error::GovernanceChatError; +use { + program_test::GovernanceChatProgramTest, solana_program_test::tokio, + solana_sdk::signature::Keypair, spl_governance::error::GovernanceError, + spl_governance_chat::error::GovernanceChatError, +}; mod program_test; diff --git a/governance/chat/program/tests/program_test/cookies.rs b/governance/chat/program/tests/program_test/cookies.rs index deac7b87743..b46dffe16f4 100644 --- a/governance/chat/program/tests/program_test/cookies.rs +++ b/governance/chat/program/tests/program_test/cookies.rs @@ -1,6 +1,7 @@ -use solana_program::pubkey::Pubkey; -use solana_sdk::signature::Keypair; -use spl_governance_chat::state::ChatMessage; +use { + solana_program::pubkey::Pubkey, solana_sdk::signature::Keypair, + spl_governance_chat::state::ChatMessage, +}; #[derive(Debug)] pub struct ChatMessageCookie { diff --git a/governance/chat/program/tests/program_test/mod.rs b/governance/chat/program/tests/program_test/mod.rs index 44d9181b3da..f9ef5c1bd23 100644 --- a/governance/chat/program/tests/program_test/mod.rs +++ b/governance/chat/program/tests/program_test/mod.rs @@ -1,36 +1,34 @@ -use std::str::FromStr; - -use solana_program::{program_error::ProgramError, pubkey::Pubkey}; -use solana_program_test::{processor, ProgramTest}; - -use solana_sdk::{signature::Keypair, signer::Signer}; -use spl_governance::{ - instruction::{ - create_governance, create_proposal, create_realm, create_token_owner_record, - deposit_governing_tokens, - }, - state::{ - enums::{MintMaxVoterWeightSource, VoteThreshold}, - governance::{ - get_governance_address, GovernanceConfig, DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, +use { + self::cookies::TokenOwnerRecordCookie, + crate::program_test::cookies::{ChatMessageCookie, ProposalCookie}, + solana_program::{program_error::ProgramError, pubkey::Pubkey}, + solana_program_test::{processor, ProgramTest}, + solana_sdk::{signature::Keypair, signer::Signer}, + spl_governance::{ + instruction::{ + create_governance, create_proposal, create_realm, create_token_owner_record, + deposit_governing_tokens, + }, + state::{ + enums::{MintMaxVoterWeightSource, VoteThreshold}, + governance::{ + get_governance_address, GovernanceConfig, DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, + }, + proposal::{get_proposal_address, VoteType}, + realm::{get_realm_address, GoverningTokenConfigAccountArgs}, + realm_config::GoverningTokenType, + token_owner_record::get_token_owner_record_address, }, - proposal::{get_proposal_address, VoteType}, - realm::{get_realm_address, GoverningTokenConfigAccountArgs}, - realm_config::GoverningTokenType, - token_owner_record::get_token_owner_record_address, }, + spl_governance_addin_mock::instruction::setup_voter_weight_record, + spl_governance_chat::{ + instruction::post_message, + processor::process_instruction, + state::{ChatMessage, GovernanceChatAccountType, MessageBody}, + }, + spl_governance_test_sdk::{addins::ensure_addin_mock_is_built, ProgramTestBench}, + std::str::FromStr, }; -use spl_governance_addin_mock::instruction::setup_voter_weight_record; -use spl_governance_chat::{ - instruction::post_message, - processor::process_instruction, - state::{ChatMessage, GovernanceChatAccountType, MessageBody}, -}; -use spl_governance_test_sdk::{addins::ensure_addin_mock_is_built, ProgramTestBench}; - -use crate::program_test::cookies::{ChatMessageCookie, ProposalCookie}; - -use self::cookies::TokenOwnerRecordCookie; pub mod cookies; diff --git a/governance/program/src/addins/max_voter_weight.rs b/governance/program/src/addins/max_voter_weight.rs index 20ad52a6961..18dc51f93cf 100644 --- a/governance/program/src/addins/max_voter_weight.rs +++ b/governance/program/src/addins/max_voter_weight.rs @@ -1,13 +1,14 @@ //! MaxVoterWeight Addin interface -use solana_program::{ - account_info::AccountInfo, clock::Clock, program_error::ProgramError, pubkey::Pubkey, - sysvar::Sysvar, +use { + crate::error::GovernanceError, + solana_program::{ + account_info::AccountInfo, clock::Clock, program_error::ProgramError, pubkey::Pubkey, + sysvar::Sysvar, + }, + spl_governance_addin_api::max_voter_weight::MaxVoterWeightRecord, + spl_governance_tools::account::get_account_data, }; -use spl_governance_addin_api::max_voter_weight::MaxVoterWeightRecord; -use spl_governance_tools::account::get_account_data; - -use crate::error::GovernanceError; /// Asserts MaxVoterWeightRecord hasn't expired pub fn assert_is_valid_max_voter_weight( diff --git a/governance/program/src/addins/voter_weight.rs b/governance/program/src/addins/voter_weight.rs index fddc931735a..24a6c534cbf 100644 --- a/governance/program/src/addins/voter_weight.rs +++ b/governance/program/src/addins/voter_weight.rs @@ -1,13 +1,14 @@ //! VoterWeight Addin interface -use solana_program::{ - account_info::AccountInfo, clock::Clock, program_error::ProgramError, pubkey::Pubkey, - sysvar::Sysvar, +use { + crate::{error::GovernanceError, state::token_owner_record::TokenOwnerRecordV2}, + solana_program::{ + account_info::AccountInfo, clock::Clock, program_error::ProgramError, pubkey::Pubkey, + sysvar::Sysvar, + }, + spl_governance_addin_api::voter_weight::{VoterWeightAction, VoterWeightRecord}, + spl_governance_tools::account::get_account_data, }; -use spl_governance_addin_api::voter_weight::{VoterWeightAction, VoterWeightRecord}; -use spl_governance_tools::account::get_account_data; - -use crate::{error::GovernanceError, state::token_owner_record::TokenOwnerRecordV2}; /// Asserts the VoterWeightRecord hasn't expired and matches the given action and target if specified pub fn assert_is_valid_voter_weight( diff --git a/governance/program/src/entrypoint.rs b/governance/program/src/entrypoint.rs index 5836ca26ddf..ce0d8210a87 100644 --- a/governance/program/src/entrypoint.rs +++ b/governance/program/src/entrypoint.rs @@ -1,10 +1,12 @@ //! Program entrypoint definitions #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use crate::{error::GovernanceError, processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::GovernanceError, processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/governance/program/src/error.rs b/governance/program/src/error.rs index 3345705583d..818082757ce 100644 --- a/governance/program/src/error.rs +++ b/governance/program/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the Governance program #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/governance/program/src/instruction.rs b/governance/program/src/instruction.rs index d0861ee61d2..ffc21708f7e 100644 --- a/governance/program/src/instruction.rs +++ b/governance/program/src/instruction.rs @@ -1,36 +1,38 @@ //! Program instructions -use crate::{ - state::{ - enums::MintMaxVoterWeightSource, - governance::{ - get_governance_address, get_mint_governance_address, get_program_governance_address, - get_token_governance_address, GovernanceConfig, +use { + crate::{ + state::{ + enums::MintMaxVoterWeightSource, + governance::{ + get_governance_address, get_mint_governance_address, + get_program_governance_address, get_token_governance_address, GovernanceConfig, + }, + native_treasury::get_native_treasury_address, + program_metadata::get_program_metadata_address, + proposal::{get_proposal_address, VoteType}, + proposal_deposit::get_proposal_deposit_address, + proposal_transaction::{get_proposal_transaction_address, InstructionData}, + realm::{ + get_governing_token_holding_address, get_realm_address, + GoverningTokenConfigAccountArgs, GoverningTokenConfigArgs, RealmConfigArgs, + SetRealmAuthorityAction, + }, + realm_config::get_realm_config_address, + required_signatory::get_required_signatory_address, + signatory_record::get_signatory_record_address, + token_owner_record::get_token_owner_record_address, + vote_record::{get_vote_record_address, Vote}, }, - native_treasury::get_native_treasury_address, - program_metadata::get_program_metadata_address, - proposal::{get_proposal_address, VoteType}, - proposal_deposit::get_proposal_deposit_address, - proposal_transaction::{get_proposal_transaction_address, InstructionData}, - realm::{ - get_governing_token_holding_address, get_realm_address, - GoverningTokenConfigAccountArgs, RealmConfigArgs, - }, - realm::{GoverningTokenConfigArgs, SetRealmAuthorityAction}, - realm_config::get_realm_config_address, - required_signatory::get_required_signatory_address, - signatory_record::get_signatory_record_address, - token_owner_record::get_token_owner_record_address, - vote_record::{get_vote_record_address, Vote}, + tools::bpf_loader_upgradeable::get_program_data_address, + }, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + bpf_loader_upgradeable, + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + system_program, sysvar, }, - tools::bpf_loader_upgradeable::get_program_data_address, -}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - bpf_loader_upgradeable, - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, }; /// Instructions supported by the Governance program diff --git a/governance/program/src/processor/mod.rs b/governance/program/src/processor/mod.rs index 9b8a84b2588..2803bd200cb 100644 --- a/governance/program/src/processor/mod.rs +++ b/governance/program/src/processor/mod.rs @@ -31,42 +31,42 @@ mod process_sign_off_proposal; mod process_update_program_metadata; mod process_withdraw_governing_tokens; -use crate::{error::GovernanceError, instruction::GovernanceInstruction}; - -use process_add_required_signatory::*; -use process_add_signatory::*; -use process_cancel_proposal::*; -use process_cast_vote::*; -use process_complete_proposal::*; -use process_create_governance::*; -use process_create_mint_governance::*; -use process_create_native_treasury::*; -use process_create_program_governance::*; -use process_create_proposal::*; -use process_create_realm::*; -use process_create_token_governance::*; -use process_create_token_owner_record::*; -use process_deposit_governing_tokens::*; -use process_execute_transaction::*; -use process_finalize_vote::*; -use process_flag_transaction_error::*; -use process_insert_transaction::*; -use process_refund_proposal_deposit::*; -use process_relinquish_vote::*; -use process_remove_required_signatory::*; -use process_remove_transaction::*; -use process_revoke_governing_tokens::*; -use process_set_governance_config::*; -use process_set_governance_delegate::*; -use process_set_realm_authority::*; -use process_set_realm_config::*; -use process_sign_off_proposal::*; -use process_update_program_metadata::*; -use process_withdraw_governing_tokens::*; - -use solana_program::{ - account_info::AccountInfo, borsh0_10::try_from_slice_unchecked, entrypoint::ProgramResult, msg, - program_error::ProgramError, pubkey::Pubkey, +use { + crate::{error::GovernanceError, instruction::GovernanceInstruction}, + process_add_required_signatory::*, + process_add_signatory::*, + process_cancel_proposal::*, + process_cast_vote::*, + process_complete_proposal::*, + process_create_governance::*, + process_create_mint_governance::*, + process_create_native_treasury::*, + process_create_program_governance::*, + process_create_proposal::*, + process_create_realm::*, + process_create_token_governance::*, + process_create_token_owner_record::*, + process_deposit_governing_tokens::*, + process_execute_transaction::*, + process_finalize_vote::*, + process_flag_transaction_error::*, + process_insert_transaction::*, + process_refund_proposal_deposit::*, + process_relinquish_vote::*, + process_remove_required_signatory::*, + process_remove_transaction::*, + process_revoke_governing_tokens::*, + process_set_governance_config::*, + process_set_governance_delegate::*, + process_set_realm_authority::*, + process_set_realm_config::*, + process_sign_off_proposal::*, + process_update_program_metadata::*, + process_withdraw_governing_tokens::*, + solana_program::{ + account_info::AccountInfo, borsh0_10::try_from_slice_unchecked, entrypoint::ProgramResult, + msg, program_error::ProgramError, pubkey::Pubkey, + }, }; /// Processes an instruction diff --git a/governance/program/src/processor/process_add_required_signatory.rs b/governance/program/src/processor/process_add_required_signatory.rs index 897939f6bcf..a3245799364 100644 --- a/governance/program/src/processor/process_add_required_signatory.rs +++ b/governance/program/src/processor/process_add_required_signatory.rs @@ -1,21 +1,22 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - governance::get_governance_data, - required_signatory::{get_required_signatory_address_seeds, RequiredSignatory}, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + governance::get_governance_data, + required_signatory::{get_required_signatory_address_seeds, RequiredSignatory}, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes AddRequiredSignatory instruction diff --git a/governance/program/src/processor/process_add_signatory.rs b/governance/program/src/processor/process_add_signatory.rs index 4cb96491123..26bdee43f74 100644 --- a/governance/program/src/processor/process_add_signatory.rs +++ b/governance/program/src/processor/process_add_signatory.rs @@ -1,24 +1,25 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - governance::get_governance_data, - proposal::get_proposal_data_for_governance, - required_signatory::get_required_signatory_data_for_governance, - signatory_record::{get_signatory_record_address_seeds, SignatoryRecordV2}, - token_owner_record::get_token_owner_record_data_for_proposal_owner, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + governance::get_governance_data, + proposal::get_proposal_data_for_governance, + required_signatory::get_required_signatory_data_for_governance, + signatory_record::{get_signatory_record_address_seeds, SignatoryRecordV2}, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes AddSignatory instruction diff --git a/governance/program/src/processor/process_cancel_proposal.rs b/governance/program/src/processor/process_cancel_proposal.rs index 83d32f857ec..bdb73a65ce9 100644 --- a/governance/program/src/processor/process_cancel_proposal.rs +++ b/governance/program/src/processor/process_cancel_proposal.rs @@ -1,17 +1,18 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, -}; - -use crate::state::{ - enums::ProposalState, governance::get_governance_data_for_realm, - proposal::get_proposal_data_for_governance, realm::assert_is_valid_realm, - token_owner_record::get_token_owner_record_data_for_proposal_owner, +use { + crate::state::{ + enums::ProposalState, governance::get_governance_data_for_realm, + proposal::get_proposal_data_for_governance, realm::assert_is_valid_realm, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; /// Processes CancelProposal instruction diff --git a/governance/program/src/processor/process_cast_vote.rs b/governance/program/src/processor/process_cast_vote.rs index 818f1e74630..7a0f93fba95 100644 --- a/governance/program/src/processor/process_cast_vote.rs +++ b/governance/program/src/processor/process_cast_vote.rs @@ -1,30 +1,31 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_addin_api::voter_weight::VoterWeightAction; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - governance::get_governance_data_for_realm, - proposal::get_proposal_data_for_governance_and_governing_mint, - realm::get_realm_data_for_governing_token_mint, - realm_config::get_realm_config_data_for_realm, - token_owner_record::{ - get_token_owner_record_data_for_proposal_owner, - get_token_owner_record_data_for_realm_and_governing_mint, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + governance::get_governance_data_for_realm, + proposal::get_proposal_data_for_governance_and_governing_mint, + realm::get_realm_data_for_governing_token_mint, + realm_config::get_realm_config_data_for_realm, + token_owner_record::{ + get_token_owner_record_data_for_proposal_owner, + get_token_owner_record_data_for_realm_and_governing_mint, + }, + vote_record::{get_vote_kind, get_vote_record_address_seeds, Vote, VoteRecordV2}, }, - vote_record::{get_vote_kind, get_vote_record_address_seeds, Vote, VoteRecordV2}, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes CastVote instruction diff --git a/governance/program/src/processor/process_complete_proposal.rs b/governance/program/src/processor/process_complete_proposal.rs index 8726484608d..6d2c017cda5 100644 --- a/governance/program/src/processor/process_complete_proposal.rs +++ b/governance/program/src/processor/process_complete_proposal.rs @@ -1,16 +1,17 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, -}; - -use crate::state::{ - enums::ProposalState, proposal::get_proposal_data, - token_owner_record::get_token_owner_record_data_for_proposal_owner, +use { + crate::state::{ + enums::ProposalState, proposal::get_proposal_data, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; /// Processes CompleteProposal instruction diff --git a/governance/program/src/processor/process_create_governance.rs b/governance/program/src/processor/process_create_governance.rs index ec3c8a73f9a..215e4005e53 100644 --- a/governance/program/src/processor/process_create_governance.rs +++ b/governance/program/src/processor/process_create_governance.rs @@ -1,26 +1,27 @@ //! Program state processor -use crate::{ - state::{ - enums::GovernanceAccountType, - governance::{ - assert_valid_create_governance_args, get_governance_address_seeds, GovernanceConfig, - GovernanceV2, +use { + crate::{ + state::{ + enums::GovernanceAccountType, + governance::{ + assert_valid_create_governance_args, get_governance_address_seeds, + GovernanceConfig, GovernanceV2, + }, + realm::get_realm_data, }, - realm::get_realm_data, + tools::structs::Reserved119, }, - tools::structs::Reserved119, -}; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, }; -use spl_governance_tools::account::create_and_serialize_account_signed; - /// Processes CreateGovernance instruction pub fn process_create_governance( program_id: &Pubkey, diff --git a/governance/program/src/processor/process_create_mint_governance.rs b/governance/program/src/processor/process_create_mint_governance.rs index 73ac74a6466..0478dd81ef8 100644 --- a/governance/program/src/processor/process_create_mint_governance.rs +++ b/governance/program/src/processor/process_create_mint_governance.rs @@ -1,30 +1,33 @@ //! Program state processor -use crate::{ - state::{ - enums::GovernanceAccountType, - governance::{ - assert_valid_create_governance_args, get_mint_governance_address_seeds, - GovernanceConfig, GovernanceV2, +use { + crate::{ + state::{ + enums::GovernanceAccountType, + governance::{ + assert_valid_create_governance_args, get_mint_governance_address_seeds, + GovernanceConfig, GovernanceV2, + }, + realm::get_realm_data, + }, + tools::{ + spl_token::{ + assert_spl_token_mint_authority_is_signer, set_spl_token_account_authority, + }, + structs::Reserved119, }, - realm::get_realm_data, }, - tools::{ - spl_token::{assert_spl_token_mint_authority_is_signer, set_spl_token_account_authority}, - structs::Reserved119, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + program_pack::Pack, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, + spl_governance_tools::account::create_and_serialize_account_signed, + spl_token::{instruction::AuthorityType, state::Mint}, }; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - program_pack::Pack, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; - -use spl_governance_tools::account::create_and_serialize_account_signed; -use spl_token::{instruction::AuthorityType, state::Mint}; /// Processes CreateMintGovernance instruction pub fn process_create_mint_governance( diff --git a/governance/program/src/processor/process_create_native_treasury.rs b/governance/program/src/processor/process_create_native_treasury.rs index b5dc8b6922f..3723f0ebabb 100644 --- a/governance/program/src/processor/process_create_native_treasury.rs +++ b/governance/program/src/processor/process_create_native_treasury.rs @@ -1,18 +1,19 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - system_program, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_with_owner_signed; - -use crate::state::{ - governance::assert_is_valid_governance, - native_treasury::{get_native_treasury_address_seeds, NativeTreasury}, +use { + crate::state::{ + governance::assert_is_valid_governance, + native_treasury::{get_native_treasury_address_seeds, NativeTreasury}, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + system_program, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_with_owner_signed, }; /// Processes CreateNativeTreasury instruction diff --git a/governance/program/src/processor/process_create_program_governance.rs b/governance/program/src/processor/process_create_program_governance.rs index e23a381540e..b3d077e2a8a 100644 --- a/governance/program/src/processor/process_create_program_governance.rs +++ b/governance/program/src/processor/process_create_program_governance.rs @@ -1,31 +1,31 @@ //! Program state processor -use crate::{ - state::governance::GovernanceV2, - state::{ - enums::GovernanceAccountType, - governance::{ - assert_valid_create_governance_args, get_program_governance_address_seeds, - GovernanceConfig, +use { + crate::{ + state::{ + enums::GovernanceAccountType, + governance::{ + assert_valid_create_governance_args, get_program_governance_address_seeds, + GovernanceConfig, GovernanceV2, + }, + realm::get_realm_data, }, - realm::get_realm_data, - }, - tools::{ - bpf_loader_upgradeable::{ - assert_program_upgrade_authority_is_signer, set_program_upgrade_authority, + tools::{ + bpf_loader_upgradeable::{ + assert_program_upgrade_authority_is_signer, set_program_upgrade_authority, + }, + structs::Reserved119, }, - structs::Reserved119, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, }; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; - -use spl_governance_tools::account::create_and_serialize_account_signed; /// Processes CreateProgramGovernance instruction pub fn process_create_program_governance( diff --git a/governance/program/src/processor/process_create_proposal.rs b/governance/program/src/processor/process_create_proposal.rs index 0259fb3077b..72f492d4200 100644 --- a/governance/program/src/processor/process_create_proposal.rs +++ b/governance/program/src/processor/process_create_proposal.rs @@ -1,31 +1,32 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_addin_api::voter_weight::VoterWeightAction; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::{GovernanceAccountType, InstructionExecutionFlags, ProposalState}, - governance::get_governance_data_for_realm, - proposal::{ - assert_valid_proposal_options, get_proposal_address_seeds, OptionVoteResult, - ProposalOption, ProposalV2, VoteType, +use { + crate::{ + error::GovernanceError, + state::{ + enums::{GovernanceAccountType, InstructionExecutionFlags, ProposalState}, + governance::get_governance_data_for_realm, + proposal::{ + assert_valid_proposal_options, get_proposal_address_seeds, OptionVoteResult, + ProposalOption, ProposalV2, VoteType, + }, + proposal_deposit::{get_proposal_deposit_address_seeds, ProposalDeposit}, + realm::get_realm_data_for_governing_token_mint, + realm_config::get_realm_config_data_for_realm, + token_owner_record::get_token_owner_record_data_for_realm, + vote_record::VoteKind, }, - proposal_deposit::{get_proposal_deposit_address_seeds, ProposalDeposit}, - realm::get_realm_data_for_governing_token_mint, - realm_config::get_realm_config_data_for_realm, - token_owner_record::get_token_owner_record_data_for_realm, - vote_record::VoteKind, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes CreateProposal instruction diff --git a/governance/program/src/processor/process_create_realm.rs b/governance/program/src/processor/process_create_realm.rs index 9a889e167d1..f299b674675 100644 --- a/governance/program/src/processor/process_create_realm.rs +++ b/governance/program/src/processor/process_create_realm.rs @@ -1,27 +1,28 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - realm::{ - assert_valid_realm_config_args, get_governing_token_holding_address_seeds, - get_realm_address_seeds, RealmConfig, RealmConfigArgs, RealmV2, - }, - realm_config::{ - get_realm_config_address_seeds, resolve_governing_token_config, RealmConfigAccount, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + realm::{ + assert_valid_realm_config_args, get_governing_token_holding_address_seeds, + get_realm_address_seeds, RealmConfig, RealmConfigArgs, RealmV2, + }, + realm_config::{ + get_realm_config_address_seeds, resolve_governing_token_config, RealmConfigAccount, + }, }, + tools::{spl_token::create_spl_token_account_signed, structs::Reserved110}, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, - tools::{spl_token::create_spl_token_account_signed, structs::Reserved110}, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes CreateRealm instruction diff --git a/governance/program/src/processor/process_create_token_governance.rs b/governance/program/src/processor/process_create_token_governance.rs index 33427a604f9..9fdd6513f70 100644 --- a/governance/program/src/processor/process_create_token_governance.rs +++ b/governance/program/src/processor/process_create_token_governance.rs @@ -1,30 +1,31 @@ //! Program state processor -use crate::{ - state::{ - enums::GovernanceAccountType, - governance::{ - assert_valid_create_governance_args, get_token_governance_address_seeds, - GovernanceConfig, GovernanceV2, +use { + crate::{ + state::{ + enums::GovernanceAccountType, + governance::{ + assert_valid_create_governance_args, get_token_governance_address_seeds, + GovernanceConfig, GovernanceV2, + }, + realm::get_realm_data, + }, + tools::{ + spl_token::{assert_spl_token_owner_is_signer, set_spl_token_account_authority}, + structs::Reserved119, }, - realm::get_realm_data, }, - tools::{ - spl_token::{assert_spl_token_owner_is_signer, set_spl_token_account_authority}, - structs::Reserved119, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + program_pack::Pack, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, + spl_governance_tools::account::create_and_serialize_account_signed, + spl_token::{instruction::AuthorityType, state::Account}, }; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - program_pack::Pack, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; - -use spl_governance_tools::account::create_and_serialize_account_signed; -use spl_token::{instruction::AuthorityType, state::Account}; /// Processes CreateTokenGovernance instruction pub fn process_create_token_governance( diff --git a/governance/program/src/processor/process_create_token_owner_record.rs b/governance/program/src/processor/process_create_token_owner_record.rs index 491668127a5..ba2b0bf91c0 100644 --- a/governance/program/src/processor/process_create_token_owner_record.rs +++ b/governance/program/src/processor/process_create_token_owner_record.rs @@ -1,24 +1,25 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - realm::get_realm_data, - token_owner_record::{ - get_token_owner_record_address_seeds, TokenOwnerRecordV2, - TOKEN_OWNER_RECORD_LAYOUT_VERSION, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + realm::get_realm_data, + token_owner_record::{ + get_token_owner_record_address_seeds, TokenOwnerRecordV2, + TOKEN_OWNER_RECORD_LAYOUT_VERSION, + }, }, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes CreateTokenOwnerRecord instruction diff --git a/governance/program/src/processor/process_deposit_governing_tokens.rs b/governance/program/src/processor/process_deposit_governing_tokens.rs index ca16fef3051..7b3271c07cb 100644 --- a/governance/program/src/processor/process_deposit_governing_tokens.rs +++ b/governance/program/src/processor/process_deposit_governing_tokens.rs @@ -1,29 +1,30 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::GovernanceAccountType, - realm::get_realm_data, - realm_config::get_realm_config_data_for_realm, - token_owner_record::{ - get_token_owner_record_address_seeds, get_token_owner_record_data_for_seeds, - TokenOwnerRecordV2, TOKEN_OWNER_RECORD_LAYOUT_VERSION, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + realm::get_realm_data, + realm_config::get_realm_config_data_for_realm, + token_owner_record::{ + get_token_owner_record_address_seeds, get_token_owner_record_data_for_seeds, + TokenOwnerRecordV2, TOKEN_OWNER_RECORD_LAYOUT_VERSION, + }, + }, + tools::spl_token::{ + get_spl_token_mint, is_spl_token_account, is_spl_token_mint, mint_spl_tokens_to, + transfer_spl_tokens, }, }, - tools::spl_token::{ - get_spl_token_mint, is_spl_token_account, is_spl_token_mint, mint_spl_tokens_to, - transfer_spl_tokens, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes DepositGoverningTokens instruction diff --git a/governance/program/src/processor/process_execute_transaction.rs b/governance/program/src/processor/process_execute_transaction.rs index a5ba79c7552..68ce104cfde 100644 --- a/governance/program/src/processor/process_execute_transaction.rs +++ b/governance/program/src/processor/process_execute_transaction.rs @@ -1,21 +1,22 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - instruction::Instruction, - program::invoke_signed, - pubkey::Pubkey, - sysvar::Sysvar, -}; - -use crate::state::{ - enums::{ProposalState, TransactionExecutionStatus}, - governance::get_governance_data, - native_treasury::get_native_treasury_address_seeds, - proposal::{get_proposal_data_for_governance, OptionVoteResult}, - proposal_transaction::get_proposal_transaction_data_for_proposal, +use { + crate::state::{ + enums::{ProposalState, TransactionExecutionStatus}, + governance::get_governance_data, + native_treasury::get_native_treasury_address_seeds, + proposal::{get_proposal_data_for_governance, OptionVoteResult}, + proposal_transaction::get_proposal_transaction_data_for_proposal, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + instruction::Instruction, + program::invoke_signed, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; /// Processes ExecuteTransaction instruction diff --git a/governance/program/src/processor/process_finalize_vote.rs b/governance/program/src/processor/process_finalize_vote.rs index c37514d0e33..23f59df939b 100644 --- a/governance/program/src/processor/process_finalize_vote.rs +++ b/governance/program/src/processor/process_finalize_vote.rs @@ -1,18 +1,20 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, -}; - -use crate::state::{ - governance::get_governance_data_for_realm, - proposal::get_proposal_data_for_governance_and_governing_mint, - realm::get_realm_data_for_governing_token_mint, realm_config::get_realm_config_data_for_realm, - token_owner_record::get_token_owner_record_data_for_proposal_owner, vote_record::VoteKind, +use { + crate::state::{ + governance::get_governance_data_for_realm, + proposal::get_proposal_data_for_governance_and_governing_mint, + realm::get_realm_data_for_governing_token_mint, + realm_config::get_realm_config_data_for_realm, + token_owner_record::get_token_owner_record_data_for_proposal_owner, vote_record::VoteKind, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; /// Processes FinalizeVote instruction diff --git a/governance/program/src/processor/process_flag_transaction_error.rs b/governance/program/src/processor/process_flag_transaction_error.rs index 1aaa145cd44..68a572488a2 100644 --- a/governance/program/src/processor/process_flag_transaction_error.rs +++ b/governance/program/src/processor/process_flag_transaction_error.rs @@ -1,18 +1,19 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, -}; - -use crate::state::{ - enums::{ProposalState, TransactionExecutionStatus}, - proposal::get_proposal_data, - proposal_transaction::get_proposal_transaction_data_for_proposal, - token_owner_record::get_token_owner_record_data_for_proposal_owner, +use { + crate::state::{ + enums::{ProposalState, TransactionExecutionStatus}, + proposal::get_proposal_data, + proposal_transaction::get_proposal_transaction_data_for_proposal, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; /// Processes FlagTransactionError instruction diff --git a/governance/program/src/processor/process_insert_transaction.rs b/governance/program/src/processor/process_insert_transaction.rs index bcf2deb640a..e73f520a269 100644 --- a/governance/program/src/processor/process_insert_transaction.rs +++ b/governance/program/src/processor/process_insert_transaction.rs @@ -1,27 +1,27 @@ //! Program state processor -use std::cmp::Ordering; - -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - enums::{GovernanceAccountType, TransactionExecutionStatus}, - governance::get_governance_data, - proposal::get_proposal_data_for_governance, - proposal_transaction::{ - get_proposal_transaction_address_seeds, InstructionData, ProposalTransactionV2, +use { + crate::{ + error::GovernanceError, + state::{ + enums::{GovernanceAccountType, TransactionExecutionStatus}, + governance::get_governance_data, + proposal::get_proposal_data_for_governance, + proposal_transaction::{ + get_proposal_transaction_address_seeds, InstructionData, ProposalTransactionV2, + }, + token_owner_record::get_token_owner_record_data_for_proposal_owner, }, - token_owner_record::get_token_owner_record_data_for_proposal_owner, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, + std::cmp::Ordering, }; /// Processes InsertTransaction instruction diff --git a/governance/program/src/processor/process_refund_proposal_deposit.rs b/governance/program/src/processor/process_refund_proposal_deposit.rs index 26985946693..dde7ddd13f6 100644 --- a/governance/program/src/processor/process_refund_proposal_deposit.rs +++ b/governance/program/src/processor/process_refund_proposal_deposit.rs @@ -1,15 +1,16 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; -use spl_governance_tools::account::dispose_account; - -use crate::state::{ - proposal::get_proposal_data, - proposal_deposit::get_proposal_deposit_data_for_proposal_and_deposit_payer, +use { + crate::state::{ + proposal::get_proposal_data, + proposal_deposit::get_proposal_deposit_data_for_proposal_and_deposit_payer, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + }, + spl_governance_tools::account::dispose_account, }; /// Processes RefundProposalDeposit instruction diff --git a/governance/program/src/processor/process_relinquish_vote.rs b/governance/program/src/processor/process_relinquish_vote.rs index f6f2d996054..ae5cdfaa097 100644 --- a/governance/program/src/processor/process_relinquish_vote.rs +++ b/governance/program/src/processor/process_relinquish_vote.rs @@ -1,24 +1,25 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, -}; -use spl_governance_tools::account::dispose_account; - -use crate::{ - error::GovernanceError, - state::{ - enums::ProposalState, - governance::get_governance_data_for_realm, - proposal::get_proposal_data_for_governance, - realm::get_realm_data_for_governing_token_mint, - token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint, - vote_record::{get_vote_record_data_for_proposal_and_token_owner_record, Vote}, +use { + crate::{ + error::GovernanceError, + state::{ + enums::ProposalState, + governance::get_governance_data_for_realm, + proposal::get_proposal_data_for_governance, + realm::get_realm_data_for_governing_token_mint, + token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint, + vote_record::{get_vote_record_data_for_proposal_and_token_owner_record, Vote}, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, }, + spl_governance_tools::account::dispose_account, }; /// Processes RelinquishVote instruction diff --git a/governance/program/src/processor/process_remove_required_signatory.rs b/governance/program/src/processor/process_remove_required_signatory.rs index 05a564c906c..c4ec93b8f19 100644 --- a/governance/program/src/processor/process_remove_required_signatory.rs +++ b/governance/program/src/processor/process_remove_required_signatory.rs @@ -1,13 +1,17 @@ -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; -use spl_governance_tools::account::dispose_account; - -use crate::{ - error::GovernanceError, state::governance::get_governance_data, - state::required_signatory::get_required_signatory_data_for_governance, +use { + crate::{ + error::GovernanceError, + state::{ + governance::get_governance_data, + required_signatory::get_required_signatory_data_for_governance, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + }, + spl_governance_tools::account::dispose_account, }; pub fn process_remove_required_signatory( diff --git a/governance/program/src/processor/process_remove_transaction.rs b/governance/program/src/processor/process_remove_transaction.rs index e89df934476..1717ade2629 100644 --- a/governance/program/src/processor/process_remove_transaction.rs +++ b/governance/program/src/processor/process_remove_transaction.rs @@ -1,15 +1,17 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; -use spl_governance_tools::account::dispose_account; - -use crate::state::{ - proposal::get_proposal_data, proposal_transaction::get_proposal_transaction_data_for_proposal, - token_owner_record::get_token_owner_record_data_for_proposal_owner, +use { + crate::state::{ + proposal::get_proposal_data, + proposal_transaction::get_proposal_transaction_data_for_proposal, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + }, + spl_governance_tools::account::dispose_account, }; /// Processes RemoveTransaction instruction diff --git a/governance/program/src/processor/process_revoke_governing_tokens.rs b/governance/program/src/processor/process_revoke_governing_tokens.rs index 72ec0535f49..cf9ea250bd9 100644 --- a/governance/program/src/processor/process_revoke_governing_tokens.rs +++ b/governance/program/src/processor/process_revoke_governing_tokens.rs @@ -1,19 +1,20 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; - -use crate::{ - error::GovernanceError, - state::{ - realm::{get_realm_address_seeds, get_realm_data}, - realm_config::get_realm_config_data_for_realm, - token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint, +use { + crate::{ + error::GovernanceError, + state::{ + realm::{get_realm_address_seeds, get_realm_data}, + realm_config::get_realm_config_data_for_realm, + token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint, + }, + tools::spl_token::{assert_spl_token_mint_authority_is_signer, burn_spl_tokens_signed}, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, }, - tools::spl_token::{assert_spl_token_mint_authority_is_signer, burn_spl_tokens_signed}, }; /// Processes RevokeGoverningTokens instruction diff --git a/governance/program/src/processor/process_set_governance_config.rs b/governance/program/src/processor/process_set_governance_config.rs index b4505c69eb4..ce6086f17b2 100644 --- a/governance/program/src/processor/process_set_governance_config.rs +++ b/governance/program/src/processor/process_set_governance_config.rs @@ -1,14 +1,17 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; - -use crate::{ - error::GovernanceError, - state::governance::{assert_is_valid_governance_config, get_governance_data, GovernanceConfig}, +use { + crate::{ + error::GovernanceError, + state::governance::{ + assert_is_valid_governance_config, get_governance_data, GovernanceConfig, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + }, }; /// Processes SetGovernanceConfig instruction diff --git a/governance/program/src/processor/process_set_governance_delegate.rs b/governance/program/src/processor/process_set_governance_delegate.rs index 6e18bf4fcfb..9d08c35ef99 100644 --- a/governance/program/src/processor/process_set_governance_delegate.rs +++ b/governance/program/src/processor/process_set_governance_delegate.rs @@ -1,13 +1,14 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, +use { + crate::state::token_owner_record::get_token_owner_record_data, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + }, }; -use crate::state::token_owner_record::get_token_owner_record_data; - /// Processes SetGovernanceDelegate instruction pub fn process_set_governance_delegate( program_id: &Pubkey, diff --git a/governance/program/src/processor/process_set_realm_authority.rs b/governance/program/src/processor/process_set_realm_authority.rs index b9e40a346a5..fc5078041d4 100644 --- a/governance/program/src/processor/process_set_realm_authority.rs +++ b/governance/program/src/processor/process_set_realm_authority.rs @@ -1,16 +1,17 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; - -use crate::{ - error::GovernanceError, - state::{ - governance::assert_governance_for_realm, - realm::{get_realm_data_for_authority, SetRealmAuthorityAction}, +use { + crate::{ + error::GovernanceError, + state::{ + governance::assert_governance_for_realm, + realm::{get_realm_data_for_authority, SetRealmAuthorityAction}, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, }, }; diff --git a/governance/program/src/processor/process_set_realm_config.rs b/governance/program/src/processor/process_set_realm_config.rs index ff033831be4..0a0f02a7c57 100644 --- a/governance/program/src/processor/process_set_realm_config.rs +++ b/governance/program/src/processor/process_set_realm_config.rs @@ -1,23 +1,26 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::{ - error::GovernanceError, - state::{ - realm::{assert_valid_realm_config_args, get_realm_data_for_authority, RealmConfigArgs}, - realm_config::{ - get_realm_config_address_seeds, get_realm_config_data_for_realm, - resolve_governing_token_config, RealmConfigAccount, +use { + crate::{ + error::GovernanceError, + state::{ + realm::{ + assert_valid_realm_config_args, get_realm_data_for_authority, RealmConfigArgs, + }, + realm_config::{ + get_realm_config_address_seeds, get_realm_config_data_for_realm, + resolve_governing_token_config, RealmConfigAccount, + }, }, }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes SetRealmConfig instruction diff --git a/governance/program/src/processor/process_sign_off_proposal.rs b/governance/program/src/processor/process_sign_off_proposal.rs index 45046601212..69a7c3b4eea 100644 --- a/governance/program/src/processor/process_sign_off_proposal.rs +++ b/governance/program/src/processor/process_sign_off_proposal.rs @@ -1,22 +1,24 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - pubkey::Pubkey, - sysvar::Sysvar, +use { + crate::{ + error::GovernanceError, + state::{ + enums::ProposalState, governance::get_governance_data_for_realm, + proposal::get_proposal_data_for_governance, realm::assert_is_valid_realm, + signatory_record::get_signatory_record_data_for_seeds, + token_owner_record::get_token_owner_record_data_for_proposal_owner, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + pubkey::Pubkey, + sysvar::Sysvar, + }, }; -use crate::state::{ - enums::ProposalState, governance::get_governance_data_for_realm, - proposal::get_proposal_data_for_governance, realm::assert_is_valid_realm, - signatory_record::get_signatory_record_data_for_seeds, - token_owner_record::get_token_owner_record_data_for_proposal_owner, -}; - -use crate::error::GovernanceError; - /// Processes SignOffProposal instruction pub fn process_sign_off_proposal(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { let account_info_iter = &mut accounts.iter(); diff --git a/governance/program/src/processor/process_update_program_metadata.rs b/governance/program/src/processor/process_update_program_metadata.rs index 1280a3f7022..fc255dc939c 100644 --- a/governance/program/src/processor/process_update_program_metadata.rs +++ b/governance/program/src/processor/process_update_program_metadata.rs @@ -1,19 +1,22 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - entrypoint::ProgramResult, - msg, - pubkey::Pubkey, - rent::Rent, - sysvar::Sysvar, -}; -use spl_governance_tools::account::create_and_serialize_account_signed; - -use crate::state::{ - enums::GovernanceAccountType, - program_metadata::{get_program_metadata_data, get_program_metadata_seeds, ProgramMetadata}, +use { + crate::state::{ + enums::GovernanceAccountType, + program_metadata::{ + get_program_metadata_data, get_program_metadata_seeds, ProgramMetadata, + }, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + entrypoint::ProgramResult, + msg, + pubkey::Pubkey, + rent::Rent, + sysvar::Sysvar, + }, + spl_governance_tools::account::create_and_serialize_account_signed, }; /// Processes UpdateProgramMetadata instruction diff --git a/governance/program/src/processor/process_withdraw_governing_tokens.rs b/governance/program/src/processor/process_withdraw_governing_tokens.rs index 0bf21474292..ac2c1fe9cc5 100644 --- a/governance/program/src/processor/process_withdraw_governing_tokens.rs +++ b/governance/program/src/processor/process_withdraw_governing_tokens.rs @@ -1,21 +1,22 @@ //! Program state processor -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - pubkey::Pubkey, -}; - -use crate::{ - error::GovernanceError, - state::{ - realm::{get_realm_address_seeds, get_realm_data}, - realm_config::get_realm_config_data_for_realm, - token_owner_record::{ - get_token_owner_record_address_seeds, get_token_owner_record_data_for_seeds, +use { + crate::{ + error::GovernanceError, + state::{ + realm::{get_realm_address_seeds, get_realm_data}, + realm_config::get_realm_config_data_for_realm, + token_owner_record::{ + get_token_owner_record_address_seeds, get_token_owner_record_data_for_seeds, + }, }, + tools::spl_token::{get_spl_token_mint, transfer_spl_tokens_signed}, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + pubkey::Pubkey, }, - tools::spl_token::{get_spl_token_mint, transfer_spl_tokens_signed}, }; /// Processes WithdrawGoverningTokens instruction diff --git a/governance/program/src/state/governance.rs b/governance/program/src/state/governance.rs index f7bcf788ab7..e09b2f0f222 100644 --- a/governance/program/src/state/governance.rs +++ b/governance/program/src/state/governance.rs @@ -1,27 +1,27 @@ //! Governance Account -use borsh::maybestd::io::Write; - -use crate::{ - error::GovernanceError, - state::{ - enums::{GovernanceAccountType, VoteThreshold, VoteTipping}, - legacy::{is_governance_v1_account_type, GovernanceV1}, - realm::{assert_is_valid_realm, RealmV2}, - vote_record::VoteKind, +use { + crate::{ + error::GovernanceError, + state::{ + enums::{GovernanceAccountType, VoteThreshold, VoteTipping}, + legacy::{is_governance_v1_account_type, GovernanceV1}, + realm::{assert_is_valid_realm, RealmV2}, + vote_record::VoteKind, + }, + tools::structs::Reserved119, }, - tools::structs::Reserved119, -}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, rent::Rent, -}; -use spl_governance_tools::{ - account::{ - assert_is_valid_account_of_types, extend_account_size, get_account_data, get_account_type, - AccountMaxSize, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, + pubkey::Pubkey, rent::Rent, + }, + spl_governance_tools::{ + account::{ + assert_is_valid_account_of_types, extend_account_size, get_account_data, + get_account_type, AccountMaxSize, + }, + error::GovernanceToolsError, }, - error::GovernanceToolsError, }; /// Governance config @@ -629,9 +629,7 @@ pub fn assert_is_valid_vote_threshold(vote_threshold: &VoteThreshold) -> Result< #[cfg(test)] mod test { - use solana_program::clock::Epoch; - - use super::*; + use {super::*, solana_program::clock::Epoch}; fn create_test_governance_config() -> GovernanceConfig { GovernanceConfig { diff --git a/governance/program/src/state/legacy.rs b/governance/program/src/state/legacy.rs index 558010d654e..e38c24d1ebe 100644 --- a/governance/program/src/state/legacy.rs +++ b/governance/program/src/state/legacy.rs @@ -1,19 +1,21 @@ //! Legacy Accounts -use crate::state::{ - enums::{ - GovernanceAccountType, InstructionExecutionFlags, ProposalState, - TransactionExecutionStatus, VoteThreshold, +use { + crate::state::{ + enums::{ + GovernanceAccountType, InstructionExecutionFlags, ProposalState, + TransactionExecutionStatus, VoteThreshold, + }, + governance::GovernanceConfig, + proposal_transaction::InstructionData, + realm::RealmConfig, + }, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + clock::{Slot, UnixTimestamp}, + program_pack::IsInitialized, + pubkey::Pubkey, }, - governance::GovernanceConfig, - proposal_transaction::InstructionData, - realm::RealmConfig, -}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - clock::{Slot, UnixTimestamp}, - program_pack::IsInitialized, - pubkey::Pubkey, }; /// Governance Realm Account diff --git a/governance/program/src/state/native_treasury.rs b/governance/program/src/state/native_treasury.rs index 8872955449c..c72ae3b1c1f 100644 --- a/governance/program/src/state/native_treasury.rs +++ b/governance/program/src/state/native_treasury.rs @@ -1,8 +1,10 @@ //! Native treasury account -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::pubkey::Pubkey; -use spl_governance_tools::account::AccountMaxSize; +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::pubkey::Pubkey, + spl_governance_tools::account::AccountMaxSize, +}; /// Treasury account /// The account has no data and can be used as a payer for instruction signed by Governance PDAs or as a native SOL treasury diff --git a/governance/program/src/state/program_metadata.rs b/governance/program/src/state/program_metadata.rs index 786b0010bff..6906c003690 100644 --- a/governance/program/src/state/program_metadata.rs +++ b/governance/program/src/state/program_metadata.rs @@ -1,13 +1,14 @@ //! ProgramMetadata Account -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, clock::Slot, program_error::ProgramError, - program_pack::IsInitialized, pubkey::Pubkey, +use { + crate::state::enums::GovernanceAccountType, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, clock::Slot, program_error::ProgramError, + program_pack::IsInitialized, pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, AccountMaxSize}, }; -use spl_governance_tools::account::{get_account_data, AccountMaxSize}; - -use crate::state::enums::GovernanceAccountType; /// Program metadata account. It stores information about the particular SPL-Governance program instance #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/program/src/state/proposal.rs b/governance/program/src/state/proposal.rs index 3eff2d92fc1..e464b9e0eaa 100644 --- a/governance/program/src/state/proposal.rs +++ b/governance/program/src/state/proposal.rs @@ -1,42 +1,38 @@ //! Proposal Account -use borsh::maybestd::io::Write; -use solana_program::account_info::next_account_info; -use std::cmp::Ordering; -use std::slice::Iter; - -use solana_program::clock::{Slot, UnixTimestamp}; - -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, -}; -use spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}; - -use crate::addins::max_voter_weight::{ - assert_is_valid_max_voter_weight, - get_max_voter_weight_record_data_for_realm_and_governing_token_mint, -}; -use crate::state::legacy::ProposalV1; -use crate::tools::spl_token::get_spl_token_mint_supply; -use crate::{ - error::GovernanceError, - state::{ - enums::{ - GovernanceAccountType, InstructionExecutionFlags, MintMaxVoterWeightSource, - ProposalState, TransactionExecutionStatus, VoteThreshold, VoteTipping, +use { + crate::{ + addins::max_voter_weight::{ + assert_is_valid_max_voter_weight, + get_max_voter_weight_record_data_for_realm_and_governing_token_mint, + }, + error::GovernanceError, + state::{ + enums::{ + GovernanceAccountType, InstructionExecutionFlags, MintMaxVoterWeightSource, + ProposalState, TransactionExecutionStatus, VoteThreshold, VoteTipping, + }, + governance::GovernanceConfig, + legacy::ProposalV1, + proposal_transaction::ProposalTransactionV2, + realm::RealmV2, + realm_config::RealmConfigAccount, + vote_record::{Vote, VoteKind}, }, - governance::GovernanceConfig, - proposal_transaction::ProposalTransactionV2, - realm::RealmV2, - vote_record::Vote, - vote_record::VoteKind, + tools::spl_token::get_spl_token_mint_supply, + PROGRAM_AUTHORITY_SEED, + }, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::{Slot, UnixTimestamp}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, }, - PROGRAM_AUTHORITY_SEED, + spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}, + std::{cmp::Ordering, slice::Iter}, }; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; - -use crate::state::realm_config::RealmConfigAccount; /// Proposal option vote result #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] @@ -1199,18 +1195,18 @@ pub fn assert_valid_proposal_options( #[cfg(test)] mod test { - use super::*; - use solana_program::clock::Epoch; - - use crate::state::{ - enums::{MintMaxVoterWeightSource, VoteThreshold}, - legacy::ProposalV1, - realm::RealmConfig, - vote_record::VoteChoice, + use { + super::*, + crate::state::{ + enums::{MintMaxVoterWeightSource, VoteThreshold}, + legacy::ProposalV1, + realm::RealmConfig, + vote_record::VoteChoice, + }, + proptest::prelude::*, + solana_program::clock::Epoch, }; - use proptest::prelude::*; - fn create_test_proposal() -> ProposalV2 { ProposalV2 { account_type: GovernanceAccountType::TokenOwnerRecordV2, diff --git a/governance/program/src/state/proposal_deposit.rs b/governance/program/src/state/proposal_deposit.rs index 6de9dc92368..06d0a9b2e61 100644 --- a/governance/program/src/state/proposal_deposit.rs +++ b/governance/program/src/state/proposal_deposit.rs @@ -1,13 +1,14 @@ //! Proposal deposit account -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, +use { + crate::{error::GovernanceError, state::enums::GovernanceAccountType}, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, AccountMaxSize}, }; -use spl_governance_tools::account::{get_account_data, AccountMaxSize}; - -use crate::{error::GovernanceError, state::enums::GovernanceAccountType}; /// Proposal deposit account /// The account is used to limit spam of proposals diff --git a/governance/program/src/state/proposal_transaction.rs b/governance/program/src/state/proposal_transaction.rs index b92b79d169e..c0f049a575b 100644 --- a/governance/program/src/state/proposal_transaction.rs +++ b/governance/program/src/state/proposal_transaction.rs @@ -1,27 +1,26 @@ //! ProposalTransaction Account -use core::panic; - -use borsh::maybestd::io::Write; - -use crate::{ - error::GovernanceError, - state::{ - enums::{GovernanceAccountType, TransactionExecutionStatus}, - legacy::ProposalInstructionV1, +use { + crate::{ + error::GovernanceError, + state::{ + enums::{GovernanceAccountType, TransactionExecutionStatus}, + legacy::ProposalInstructionV1, + }, + PROGRAM_AUTHORITY_SEED, }, - PROGRAM_AUTHORITY_SEED, -}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, - clock::UnixTimestamp, - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - program_pack::IsInitialized, - pubkey::Pubkey, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + core::panic, + solana_program::{ + account_info::AccountInfo, + clock::UnixTimestamp, + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}, }; -use spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}; /// InstructionData wrapper. It can be removed once Borsh serialization for Instruction is supported in the SDK #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/program/src/state/realm.rs b/governance/program/src/state/realm.rs index 3027b770234..86f368676e0 100644 --- a/governance/program/src/state/realm.rs +++ b/governance/program/src/state/realm.rs @@ -1,34 +1,31 @@ //! Realm Account -use borsh::maybestd::io::Write; -use std::slice::Iter; - -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - program_error::ProgramError, - program_pack::IsInitialized, - pubkey::Pubkey, -}; -use spl_governance_addin_api::voter_weight::VoterWeightAction; -use spl_governance_tools::account::{ - assert_is_valid_account_of_types, get_account_data, get_account_type, AccountMaxSize, -}; - -use crate::{ - error::GovernanceError, - state::{ - enums::{GovernanceAccountType, MintMaxVoterWeightSource}, - legacy::RealmV1, - realm_config::GoverningTokenType, - token_owner_record::get_token_owner_record_data_for_realm, - vote_record::VoteKind, +use { + crate::{ + error::GovernanceError, + state::{ + enums::{GovernanceAccountType, MintMaxVoterWeightSource}, + legacy::RealmV1, + realm_config::{get_realm_config_data_for_realm, GoverningTokenType}, + token_owner_record::get_token_owner_record_data_for_realm, + vote_record::VoteKind, + }, + PROGRAM_AUTHORITY_SEED, }, - PROGRAM_AUTHORITY_SEED, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, + spl_governance_tools::account::{ + assert_is_valid_account_of_types, get_account_data, get_account_type, AccountMaxSize, + }, + std::slice::Iter, }; -use crate::state::realm_config::get_realm_config_data_for_realm; - /// Realm Config instruction args #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] pub struct RealmConfigArgs { @@ -457,10 +454,10 @@ pub fn assert_valid_realm_config_args( #[cfg(test)] mod test { - use crate::instruction::GovernanceInstruction; - use solana_program::borsh0_10::try_from_slice_unchecked; - - use super::*; + use { + super::*, crate::instruction::GovernanceInstruction, + solana_program::borsh0_10::try_from_slice_unchecked, + }; #[test] fn test_max_size() { diff --git a/governance/program/src/state/realm_config.rs b/governance/program/src/state/realm_config.rs index 21904e5cd93..1ddd2a8f7e1 100644 --- a/governance/program/src/state/realm_config.rs +++ b/governance/program/src/state/realm_config.rs @@ -1,23 +1,24 @@ //! RealmConfig account -use std::slice::Iter; - -use solana_program::account_info::next_account_info; - -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + realm::{GoverningTokenConfigArgs, RealmConfigArgs, RealmV2}, + }, + tools::structs::Reserved110, + }, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, AccountMaxSize}, + std::slice::Iter, }; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use spl_governance_tools::account::{get_account_data, AccountMaxSize}; - -use crate::tools::structs::Reserved110; -use crate::{error::GovernanceError, state::enums::GovernanceAccountType}; - -use crate::state::realm::GoverningTokenConfigArgs; - -use crate::state::realm::{RealmConfigArgs, RealmV2}; - /// The type of the governing token defines: /// 1) Who retains the authority over deposited tokens /// 2) Which token instructions Deposit, Withdraw and Revoke (burn) are allowed @@ -281,8 +282,10 @@ pub fn resolve_governing_token_config( #[cfg(test)] mod test { - use super::*; - use crate::state::{enums::GovernanceAccountType, realm_config::RealmConfigAccount}; + use { + super::*, + crate::state::{enums::GovernanceAccountType, realm_config::RealmConfigAccount}, + }; #[test] fn test_max_size() { diff --git a/governance/program/src/state/required_signatory.rs b/governance/program/src/state/required_signatory.rs index bd0a302c95b..c1b4d747179 100644 --- a/governance/program/src/state/required_signatory.rs +++ b/governance/program/src/state/required_signatory.rs @@ -1,11 +1,13 @@ //! RequiredSignatory account -use crate::{error::GovernanceError, state::enums::GovernanceAccountType}; -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, +use { + crate::{error::GovernanceError, state::enums::GovernanceAccountType}, + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, AccountMaxSize}, }; -use spl_governance_tools::account::{get_account_data, AccountMaxSize}; /// Required signatory #[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/program/src/state/signatory_record.rs b/governance/program/src/state/signatory_record.rs index 7cdd4684472..db60c6ccf42 100644 --- a/governance/program/src/state/signatory_record.rs +++ b/governance/program/src/state/signatory_record.rs @@ -1,18 +1,18 @@ //! Signatory Record -use borsh::maybestd::io::Write; - -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; - -use solana_program::{ - account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, - pubkey::Pubkey, +use { + crate::{ + error::GovernanceError, + state::{enums::GovernanceAccountType, legacy::SignatoryRecordV1}, + PROGRAM_AUTHORITY_SEED, + }, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}, }; -use spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}; - -use crate::{error::GovernanceError, PROGRAM_AUTHORITY_SEED}; - -use crate::state::{enums::GovernanceAccountType, legacy::SignatoryRecordV1}; /// Account PDA seeds: ['governance', proposal, signatory] #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/program/src/state/token_owner_record.rs b/governance/program/src/state/token_owner_record.rs index 846dcd9b0bf..2ea3ef5c692 100644 --- a/governance/program/src/state/token_owner_record.rs +++ b/governance/program/src/state/token_owner_record.rs @@ -1,31 +1,28 @@ //! Token Owner Record Account -use borsh::maybestd::io::Write; -use std::slice::Iter; - -use crate::{ - addins::voter_weight::{ - assert_is_valid_voter_weight, get_voter_weight_record_data_for_token_owner_record, +use { + crate::{ + addins::voter_weight::{ + assert_is_valid_voter_weight, get_voter_weight_record_data_for_token_owner_record, + }, + error::GovernanceError, + state::{ + enums::GovernanceAccountType, governance::GovernanceConfig, legacy::TokenOwnerRecordV1, + realm::RealmV2, realm_config::RealmConfigAccount, + }, + PROGRAM_AUTHORITY_SEED, }, - error::GovernanceError, - state::{ - enums::GovernanceAccountType, governance::GovernanceConfig, legacy::TokenOwnerRecordV1, - realm::RealmV2, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, }, - PROGRAM_AUTHORITY_SEED, -}; - -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - program_error::ProgramError, - program_pack::IsInitialized, - pubkey::Pubkey, + spl_governance_addin_api::voter_weight::VoterWeightAction, + spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}, + std::slice::Iter, }; -use spl_governance_addin_api::voter_weight::VoterWeightAction; -use spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}; - -use crate::state::realm_config::RealmConfigAccount; /// Governance Token Owner Record /// Account PDA seeds: ['governance', realm, token_mint, token_owner ] @@ -422,9 +419,10 @@ pub fn get_token_owner_record_data_for_proposal_owner( #[cfg(test)] mod test { - use solana_program::{borsh0_10::get_packed_len, stake_history::Epoch}; - - use super::*; + use { + super::*, + solana_program::{borsh0_10::get_packed_len, stake_history::Epoch}, + }; fn create_test_token_owner_record() -> TokenOwnerRecordV2 { TokenOwnerRecordV2 { diff --git a/governance/program/src/state/vote_record.rs b/governance/program/src/state/vote_record.rs index d539c91b84a..efa02c797aa 100644 --- a/governance/program/src/state/vote_record.rs +++ b/governance/program/src/state/vote_record.rs @@ -1,24 +1,23 @@ //! Proposal Vote Record Account -use borsh::maybestd::io::Write; - -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::account_info::AccountInfo; - -use solana_program::program_error::ProgramError; -use solana_program::{program_pack::IsInitialized, pubkey::Pubkey}; -use spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}; - -use crate::error::GovernanceError; - -use crate::PROGRAM_AUTHORITY_SEED; - -use crate::state::{ - enums::GovernanceAccountType, - legacy::{VoteRecordV1, VoteWeightV1}, - proposal::ProposalV2, - realm::RealmV2, - token_owner_record::TokenOwnerRecordV2, +use { + crate::{ + error::GovernanceError, + state::{ + enums::GovernanceAccountType, + legacy::{VoteRecordV1, VoteWeightV1}, + proposal::ProposalV2, + realm::RealmV2, + token_owner_record::TokenOwnerRecordV2, + }, + PROGRAM_AUTHORITY_SEED, + }, + borsh::{maybestd::io::Write, BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, program_error::ProgramError, program_pack::IsInitialized, + pubkey::Pubkey, + }, + spl_governance_tools::account::{get_account_data, get_account_type, AccountMaxSize}, }; /// Voter choice for a proposal option @@ -264,9 +263,7 @@ pub fn get_vote_record_address<'a>( #[cfg(test)] mod test { - use solana_program::clock::Epoch; - - use super::*; + use {super::*, solana_program::clock::Epoch}; #[test] fn test_vote_record_v1_to_v2_serialisation_roundtrip() { diff --git a/governance/program/src/tools/bpf_loader_upgradeable.rs b/governance/program/src/tools/bpf_loader_upgradeable.rs index bffde9afdbf..c3ec4db16c7 100644 --- a/governance/program/src/tools/bpf_loader_upgradeable.rs +++ b/governance/program/src/tools/bpf_loader_upgradeable.rs @@ -1,17 +1,17 @@ //! General purpose bpf_loader_upgradeable utility functions -use solana_program::{ - account_info::AccountInfo, - bpf_loader_upgradeable::{self, UpgradeableLoaderState}, - program::invoke, - program_error::ProgramError, - pubkey::Pubkey, +use { + crate::error::GovernanceError, + bincode::deserialize, + solana_program::{ + account_info::AccountInfo, + bpf_loader_upgradeable::{self, UpgradeableLoaderState}, + program::invoke, + program_error::ProgramError, + pubkey::Pubkey, + }, }; -use bincode::deserialize; - -use crate::error::GovernanceError; - /// Returns ProgramData account address for the given Program pub fn get_program_data_address(program: &Pubkey) -> Pubkey { Pubkey::find_program_address(&[program.as_ref()], &bpf_loader_upgradeable::id()).0 diff --git a/governance/program/src/tools/pack.rs b/governance/program/src/tools/pack.rs index a503649fd12..809d3b296ee 100644 --- a/governance/program/src/tools/pack.rs +++ b/governance/program/src/tools/pack.rs @@ -1,7 +1,9 @@ //! General purpose packing utility functions -use arrayref::array_refs; -use solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey}; +use { + arrayref::array_refs, + solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey}, +}; /// Unpacks COption from a slice pub fn unpack_coption_pubkey(src: &[u8; 36]) -> Result, ProgramError> { diff --git a/governance/program/src/tools/spl_token.rs b/governance/program/src/tools/spl_token.rs index b7659f82804..9b9474a7f3a 100644 --- a/governance/program/src/tools/spl_token.rs +++ b/governance/program/src/tools/spl_token.rs @@ -1,24 +1,25 @@ //! General purpose SPL token utility functions -use arrayref::array_ref; -use solana_program::{ - account_info::AccountInfo, - entrypoint::ProgramResult, - msg, - program::{invoke, invoke_signed}, - program_error::ProgramError, - program_option::COption, - program_pack::Pack, - pubkey::Pubkey, - rent::Rent, - system_instruction, +use { + crate::{error::GovernanceError, tools::pack::unpack_coption_pubkey}, + arrayref::array_ref, + solana_program::{ + account_info::AccountInfo, + entrypoint::ProgramResult, + msg, + program::{invoke, invoke_signed}, + program_error::ProgramError, + program_option::COption, + program_pack::Pack, + pubkey::Pubkey, + rent::Rent, + system_instruction, + }, + spl_token::{ + instruction::{set_authority, AuthorityType}, + state::{Account, Mint}, + }, }; -use spl_token::{ - instruction::{set_authority, AuthorityType}, - state::{Account, Mint}, -}; - -use crate::{error::GovernanceError, tools::pack::unpack_coption_pubkey}; /// Creates and initializes SPL token account with PDA using the provided PDA seeds #[allow(clippy::too_many_arguments)] diff --git a/governance/program/tests/migrate_legacy_accounts.rs b/governance/program/tests/migrate_legacy_accounts.rs index d9c39097f68..81db08665ae 100644 --- a/governance/program/tests/migrate_legacy_accounts.rs +++ b/governance/program/tests/migrate_legacy_accounts.rs @@ -4,12 +4,12 @@ use solana_program_test::*; mod program_test; -use program_test::legacy::*; -use program_test::*; - -use spl_governance::state::{ - enums::{VoteThreshold, VoteTipping}, - governance::DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, +use { + program_test::{legacy::*, *}, + spl_governance::state::{ + enums::{VoteThreshold, VoteTipping}, + governance::DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, + }, }; #[tokio::test] diff --git a/governance/program/tests/process_add_required_signatory.rs b/governance/program/tests/process_add_required_signatory.rs index 0f0d161600e..d4a197c65af 100644 --- a/governance/program/tests/process_add_required_signatory.rs +++ b/governance/program/tests/process_add_required_signatory.rs @@ -2,16 +2,16 @@ mod program_test; -use solana_program_test::tokio; - -use num_traits::cast::ToPrimitive; -use program_test::*; -use solana_program::{ - program_error::ProgramError, pubkey::Pubkey, system_instruction::SystemError, +use { + num_traits::cast::ToPrimitive, + program_test::*, + solana_program::{ + program_error::ProgramError, pubkey::Pubkey, system_instruction::SystemError, + }, + solana_program_test::tokio, + solana_sdk::signature::Signer, + spl_governance::{error::GovernanceError, instruction::add_required_signatory}, }; -use solana_sdk::signature::Signer; -use spl_governance::error::GovernanceError; -use spl_governance::instruction::add_required_signatory; #[tokio::test] async fn test_add_required_signatory() { diff --git a/governance/program/tests/process_add_signatory.rs b/governance/program/tests/process_add_signatory.rs index f7107e23160..7c9b15507bb 100644 --- a/governance/program/tests/process_add_signatory.rs +++ b/governance/program/tests/process_add_signatory.rs @@ -2,16 +2,16 @@ mod program_test; -use solana_program::program_error::ProgramError; -use solana_program_test::tokio; - -use borsh::BorshSerialize; -use program_test::*; -use solana_sdk::{pubkey::Pubkey, signature::Signer}; - -use spl_governance::{ - error::GovernanceError, - instruction::{add_signatory, AddSignatoryAuthority, GovernanceInstruction}, +use { + borsh::BorshSerialize, + program_test::*, + solana_program::program_error::ProgramError, + solana_program_test::tokio, + solana_sdk::{pubkey::Pubkey, signature::Signer}, + spl_governance::{ + error::GovernanceError, + instruction::{add_signatory, AddSignatoryAuthority, GovernanceInstruction}, + }, }; #[tokio::test] diff --git a/governance/program/tests/process_cancel_proposal.rs b/governance/program/tests/process_cancel_proposal.rs index 53e7c4e3eaa..81d68ed2f0c 100644 --- a/governance/program/tests/process_cancel_proposal.rs +++ b/governance/program/tests/process_cancel_proposal.rs @@ -2,10 +2,11 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::{error::GovernanceError, state::enums::ProposalState}; +use { + program_test::*, + solana_program_test::tokio, + spl_governance::{error::GovernanceError, state::enums::ProposalState}, +}; #[tokio::test] async fn test_cancel_proposal() { diff --git a/governance/program/tests/process_cast_vote.rs b/governance/program/tests/process_cast_vote.rs index 99be08ebfad..c9b1a272b99 100644 --- a/governance/program/tests/process_cast_vote.rs +++ b/governance/program/tests/process_cast_vote.rs @@ -2,20 +2,20 @@ mod program_test; -use solana_program::pubkey::Pubkey; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::{ - error::GovernanceError, - state::{ - enums::{MintMaxVoterWeightSource, ProposalState, VoteThreshold, VoteTipping}, - vote_record::Vote, +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + solana_program::pubkey::Pubkey, + solana_program_test::tokio, + spl_governance::{ + error::GovernanceError, + state::{ + enums::{MintMaxVoterWeightSource, ProposalState, VoteThreshold, VoteTipping}, + vote_record::Vote, + }, }, }; -use crate::program_test::args::RealmSetupArgs; - #[tokio::test] async fn test_cast_vote() { // Arrange diff --git a/governance/program/tests/process_complete_proposal.rs b/governance/program/tests/process_complete_proposal.rs index b42e4ca5425..99700613b09 100644 --- a/governance/program/tests/process_complete_proposal.rs +++ b/governance/program/tests/process_complete_proposal.rs @@ -2,11 +2,11 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::error::GovernanceError; -use spl_governance::state::enums::ProposalState; +use { + program_test::*, + solana_program_test::tokio, + spl_governance::{error::GovernanceError, state::enums::ProposalState}, +}; #[tokio::test] async fn test_complete_proposal() { diff --git a/governance/program/tests/process_create_governance.rs b/governance/program/tests/process_create_governance.rs index e91c6865620..220de723d73 100644 --- a/governance/program/tests/process_create_governance.rs +++ b/governance/program/tests/process_create_governance.rs @@ -1,13 +1,14 @@ #![cfg(feature = "test-sbf")] mod program_test; -use solana_program_test::*; - -use crate::program_test::args::RealmSetupArgs; -use program_test::*; -use solana_sdk::signature::Keypair; -use spl_governance::{error::GovernanceError, state::enums::VoteThreshold}; -use spl_governance_tools::error::GovernanceToolsError; +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + solana_program_test::*, + solana_sdk::signature::Keypair, + spl_governance::{error::GovernanceError, state::enums::VoteThreshold}, + spl_governance_tools::error::GovernanceToolsError, +}; #[tokio::test] async fn test_create_governance() { diff --git a/governance/program/tests/process_create_mint_governance.rs b/governance/program/tests/process_create_mint_governance.rs index 82fb83f401b..13852aa7760 100644 --- a/governance/program/tests/process_create_mint_governance.rs +++ b/governance/program/tests/process_create_mint_governance.rs @@ -1,13 +1,14 @@ #![cfg(feature = "test-sbf")] mod program_test; -use solana_program_test::*; - -use program_test::*; -use solana_sdk::{signature::Keypair, signer::Signer}; -use spl_governance::error::GovernanceError; -use spl_governance_tools::error::GovernanceToolsError; -use spl_token::error::TokenError; +use { + program_test::*, + solana_program_test::*, + solana_sdk::{signature::Keypair, signer::Signer}, + spl_governance::error::GovernanceError, + spl_governance_tools::error::GovernanceToolsError, + spl_token::error::TokenError, +}; #[tokio::test] async fn test_create_mint_governance() { diff --git a/governance/program/tests/process_create_program_governance.rs b/governance/program/tests/process_create_program_governance.rs index 332e95cf2f9..2bd19172c6b 100644 --- a/governance/program/tests/process_create_program_governance.rs +++ b/governance/program/tests/process_create_program_governance.rs @@ -1,15 +1,16 @@ #![cfg(feature = "test-sbf")] mod program_test; -use solana_program_test::*; - -use program_test::*; -use solana_sdk::signature::{Keypair, Signer}; -use spl_governance::{ - error::GovernanceError, tools::bpf_loader_upgradeable::get_program_upgrade_authority, +use { + program_test::*, + solana_program_test::*, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{ + error::GovernanceError, tools::bpf_loader_upgradeable::get_program_upgrade_authority, + }, + spl_governance_test_sdk::tools::ProgramInstructionError, + spl_governance_tools::error::GovernanceToolsError, }; -use spl_governance_test_sdk::tools::ProgramInstructionError; -use spl_governance_tools::error::GovernanceToolsError; #[tokio::test] async fn test_create_program_governance() { diff --git a/governance/program/tests/process_create_proposal.rs b/governance/program/tests/process_create_proposal.rs index 31680c0226c..021d66fc949 100644 --- a/governance/program/tests/process_create_proposal.rs +++ b/governance/program/tests/process_create_proposal.rs @@ -1,17 +1,21 @@ #![cfg(feature = "test-sbf")] -use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; -use solana_program_test::*; +use { + solana_program::{instruction::AccountMeta, pubkey::Pubkey}, + solana_program_test::*, +}; mod program_test; -use program_test::*; -use solana_sdk::signature::Keypair; -use spl_governance::{ - error::GovernanceError, - state::{enums::VoteThreshold, governance::SECURITY_DEPOSIT_BASE_LAMPORTS}, +use { + program_test::*, + solana_sdk::signature::Keypair, + spl_governance::{ + error::GovernanceError, + state::{enums::VoteThreshold, governance::SECURITY_DEPOSIT_BASE_LAMPORTS}, + }, + spl_governance_tools::account::AccountMaxSize, }; -use spl_governance_tools::account::AccountMaxSize; #[tokio::test] async fn test_create_community_proposal() { diff --git a/governance/program/tests/process_create_realm.rs b/governance/program/tests/process_create_realm.rs index 8a61dd6da26..d380bcbcb0b 100644 --- a/governance/program/tests/process_create_realm.rs +++ b/governance/program/tests/process_create_realm.rs @@ -4,10 +4,11 @@ use solana_program_test::*; mod program_test; -use program_test::*; -use spl_governance::state::{enums::MintMaxVoterWeightSource, realm::get_realm_address}; - -use crate::program_test::args::RealmSetupArgs; +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + spl_governance::state::{enums::MintMaxVoterWeightSource, realm::get_realm_address}, +}; #[tokio::test] async fn test_create_realm() { diff --git a/governance/program/tests/process_create_token_governance.rs b/governance/program/tests/process_create_token_governance.rs index 2c5cf14ede8..6d880ec5a91 100644 --- a/governance/program/tests/process_create_token_governance.rs +++ b/governance/program/tests/process_create_token_governance.rs @@ -1,14 +1,14 @@ #![cfg(feature = "test-sbf")] mod program_test; -use solana_program_test::*; - -use program_test::*; -use solana_sdk::{signature::Keypair, signer::Signer}; -use spl_governance::error::GovernanceError; -use spl_governance_tools::error::GovernanceToolsError; - -use spl_token::{error::TokenError, instruction::AuthorityType}; +use { + program_test::*, + solana_program_test::*, + solana_sdk::{signature::Keypair, signer::Signer}, + spl_governance::error::GovernanceError, + spl_governance_tools::error::GovernanceToolsError, + spl_token::{error::TokenError, instruction::AuthorityType}, +}; #[tokio::test] async fn test_create_token_governance() { diff --git a/governance/program/tests/process_create_token_owner_record.rs b/governance/program/tests/process_create_token_owner_record.rs index 5eb0917dfdd..99b47f74c7e 100644 --- a/governance/program/tests/process_create_token_owner_record.rs +++ b/governance/program/tests/process_create_token_owner_record.rs @@ -4,8 +4,9 @@ use solana_program_test::*; mod program_test; -use program_test::*; -use spl_governance::state::token_owner_record::TOKEN_OWNER_RECORD_LAYOUT_VERSION; +use { + program_test::*, spl_governance::state::token_owner_record::TOKEN_OWNER_RECORD_LAYOUT_VERSION, +}; #[tokio::test] async fn test_create_token_owner_record() { diff --git a/governance/program/tests/process_deposit_governing_tokens.rs b/governance/program/tests/process_deposit_governing_tokens.rs index 175b01543ce..bd921685a42 100644 --- a/governance/program/tests/process_deposit_governing_tokens.rs +++ b/governance/program/tests/process_deposit_governing_tokens.rs @@ -1,22 +1,22 @@ #![cfg(feature = "test-sbf")] -use solana_program::instruction::AccountMeta; -use solana_program_test::*; +use {solana_program::instruction::AccountMeta, solana_program_test::*}; mod program_test; -use program_test::*; -use solana_sdk::signature::{Keypair, Signer}; -use spl_governance::{ - error::GovernanceError, - instruction::deposit_governing_tokens, - state::{ - realm_config::GoverningTokenType, token_owner_record::TOKEN_OWNER_RECORD_LAYOUT_VERSION, +use { + crate::program_test::args::*, + program_test::*, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{ + error::GovernanceError, + instruction::deposit_governing_tokens, + state::{ + realm_config::GoverningTokenType, token_owner_record::TOKEN_OWNER_RECORD_LAYOUT_VERSION, + }, }, }; -use crate::program_test::args::*; - #[tokio::test] async fn test_deposit_initial_community_tokens() { // Arrange diff --git a/governance/program/tests/process_execute_transaction.rs b/governance/program/tests/process_execute_transaction.rs index 97b3381426b..b6d2073a08b 100644 --- a/governance/program/tests/process_execute_transaction.rs +++ b/governance/program/tests/process_execute_transaction.rs @@ -2,17 +2,18 @@ mod program_test; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - sysvar::clock, -}; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::{ - error::GovernanceError, - state::enums::{ProposalState, TransactionExecutionStatus}, +use { + program_test::*, + solana_program::{ + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + sysvar::clock, + }, + solana_program_test::tokio, + spl_governance::{ + error::GovernanceError, + state::enums::{ProposalState, TransactionExecutionStatus}, + }, }; #[tokio::test] diff --git a/governance/program/tests/process_finalize_vote.rs b/governance/program/tests/process_finalize_vote.rs index 6431228d85b..626f0359085 100644 --- a/governance/program/tests/process_finalize_vote.rs +++ b/governance/program/tests/process_finalize_vote.rs @@ -2,12 +2,13 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::{ - error::GovernanceError, - state::enums::{ProposalState, VoteThreshold}, +use { + program_test::*, + solana_program_test::tokio, + spl_governance::{ + error::GovernanceError, + state::enums::{ProposalState, VoteThreshold}, + }, }; #[tokio::test] diff --git a/governance/program/tests/process_flag_transaction_error.rs b/governance/program/tests/process_flag_transaction_error.rs index 30f5f55ab56..21878317b1e 100644 --- a/governance/program/tests/process_flag_transaction_error.rs +++ b/governance/program/tests/process_flag_transaction_error.rs @@ -2,12 +2,13 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::{ - error::GovernanceError, - state::enums::{ProposalState, TransactionExecutionStatus}, +use { + program_test::*, + solana_program_test::tokio, + spl_governance::{ + error::GovernanceError, + state::enums::{ProposalState, TransactionExecutionStatus}, + }, }; #[tokio::test] diff --git a/governance/program/tests/process_insert_transaction.rs b/governance/program/tests/process_insert_transaction.rs index 449e477a6c4..648d773fdfc 100644 --- a/governance/program/tests/process_insert_transaction.rs +++ b/governance/program/tests/process_insert_transaction.rs @@ -2,10 +2,7 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::error::GovernanceError; +use {program_test::*, solana_program_test::tokio, spl_governance::error::GovernanceError}; #[tokio::test] async fn test_insert_transaction() { diff --git a/governance/program/tests/process_refund_proposal_deposit.rs b/governance/program/tests/process_refund_proposal_deposit.rs index e7569431e4f..ff367aa345e 100644 --- a/governance/program/tests/process_refund_proposal_deposit.rs +++ b/governance/program/tests/process_refund_proposal_deposit.rs @@ -1,12 +1,10 @@ #![cfg(feature = "test-sbf")] -use solana_program::program_error::ProgramError; -use solana_program_test::*; +use {solana_program::program_error::ProgramError, solana_program_test::*}; mod program_test; -use program_test::*; -use spl_governance::error::GovernanceError; +use {program_test::*, spl_governance::error::GovernanceError}; #[tokio::test] async fn test_refund_proposal_deposit() { diff --git a/governance/program/tests/process_relinquish_vote.rs b/governance/program/tests/process_relinquish_vote.rs index e87244fc626..682e0aaa668 100644 --- a/governance/program/tests/process_relinquish_vote.rs +++ b/governance/program/tests/process_relinquish_vote.rs @@ -2,17 +2,18 @@ mod program_test; -use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; -use solana_program_test::tokio; - -use program_test::*; -use solana_sdk::signer::Signer; -use spl_governance::{ - error::GovernanceError, - instruction::{cast_vote, relinquish_vote}, - state::{ - enums::{ProposalState, VoteTipping}, - vote_record::{Vote, VoteChoice}, +use { + program_test::*, + solana_program::{instruction::AccountMeta, pubkey::Pubkey}, + solana_program_test::tokio, + solana_sdk::signer::Signer, + spl_governance::{ + error::GovernanceError, + instruction::{cast_vote, relinquish_vote}, + state::{ + enums::{ProposalState, VoteTipping}, + vote_record::{Vote, VoteChoice}, + }, }, }; diff --git a/governance/program/tests/process_remove_required_signatory.rs b/governance/program/tests/process_remove_required_signatory.rs index 6c001de7833..12c39a9fed7 100644 --- a/governance/program/tests/process_remove_required_signatory.rs +++ b/governance/program/tests/process_remove_required_signatory.rs @@ -2,15 +2,14 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use solana_program::pubkey::Pubkey; -use spl_governance::instruction::remove_required_signatory; - -use solana_sdk::signature::Signer; -use spl_governance::error::GovernanceError; -use spl_governance_tools::error::GovernanceToolsError; +use { + program_test::*, + solana_program::pubkey::Pubkey, + solana_program_test::tokio, + solana_sdk::signature::Signer, + spl_governance::{error::GovernanceError, instruction::remove_required_signatory}, + spl_governance_tools::error::GovernanceToolsError, +}; #[tokio::test] async fn test_remove_required_signatory() { diff --git a/governance/program/tests/process_remove_transaction.rs b/governance/program/tests/process_remove_transaction.rs index 6aec9c71e7a..520ab8444e0 100644 --- a/governance/program/tests/process_remove_transaction.rs +++ b/governance/program/tests/process_remove_transaction.rs @@ -2,10 +2,7 @@ mod program_test; -use solana_program_test::tokio; - -use program_test::*; -use spl_governance::error::GovernanceError; +use {program_test::*, solana_program_test::tokio, spl_governance::error::GovernanceError}; #[tokio::test] async fn test_remove_transaction() { diff --git a/governance/program/tests/process_revoke_governing_tokens.rs b/governance/program/tests/process_revoke_governing_tokens.rs index 04804530d1d..5a038c85f82 100644 --- a/governance/program/tests/process_revoke_governing_tokens.rs +++ b/governance/program/tests/process_revoke_governing_tokens.rs @@ -1,20 +1,19 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::*; - -use spl_governance::{ - error::GovernanceError, - state::{realm::get_governing_token_holding_address, realm_config::GoverningTokenType}, +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{ + error::GovernanceError, + state::{realm::get_governing_token_holding_address, realm_config::GoverningTokenType}, + }, + spl_governance_test_sdk::tools::{clone_keypair, NopOverride}, }; -use spl_governance_test_sdk::tools::{clone_keypair, NopOverride}; - -use crate::program_test::args::RealmSetupArgs; -use solana_sdk::signature::{Keypair, Signer}; #[tokio::test] async fn test_revoke_community_tokens() { diff --git a/governance/program/tests/process_set_governance_config.rs b/governance/program/tests/process_set_governance_config.rs index 410580f1398..633d779d157 100644 --- a/governance/program/tests/process_set_governance_config.rs +++ b/governance/program/tests/process_set_governance_config.rs @@ -2,15 +2,16 @@ mod program_test; -use program_test::*; -use solana_program_test::tokio; -use solana_sdk::{signature::Keypair, signer::Signer}; -use spl_governance::{ - error::GovernanceError, instruction::set_governance_config, state::enums::VoteThreshold, +use { + program_test::*, + solana_program_test::tokio, + solana_sdk::{signature::Keypair, signer::Signer}, + spl_governance::{ + error::GovernanceError, instruction::set_governance_config, state::enums::VoteThreshold, + }, + spl_governance_test_sdk::tools::ProgramInstructionError, + spl_governance_tools::error::GovernanceToolsError, }; -use spl_governance_test_sdk::tools::ProgramInstructionError; - -use spl_governance_tools::error::GovernanceToolsError; #[tokio::test] async fn test_set_governance_config() { diff --git a/governance/program/tests/process_set_governance_delegate.rs b/governance/program/tests/process_set_governance_delegate.rs index d9050798b0e..1c468eb2d24 100644 --- a/governance/program/tests/process_set_governance_delegate.rs +++ b/governance/program/tests/process_set_governance_delegate.rs @@ -1,13 +1,14 @@ #![cfg(feature = "test-sbf")] -use solana_program::instruction::AccountMeta; -use solana_program_test::*; +use {solana_program::instruction::AccountMeta, solana_program_test::*}; mod program_test; -use program_test::*; -use solana_sdk::signature::{Keypair, Signer}; -use spl_governance::{error::GovernanceError, instruction::set_governance_delegate}; +use { + program_test::*, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{error::GovernanceError, instruction::set_governance_delegate}, +}; #[tokio::test] async fn test_set_community_governance_delegate() { diff --git a/governance/program/tests/process_set_realm_authority.rs b/governance/program/tests/process_set_realm_authority.rs index 4628e82d35a..0a8c0c7f8a9 100644 --- a/governance/program/tests/process_set_realm_authority.rs +++ b/governance/program/tests/process_set_realm_authority.rs @@ -1,13 +1,13 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::*; -use spl_governance::error::GovernanceError; -use spl_governance_tools::error::GovernanceToolsError; +use { + program_test::*, spl_governance::error::GovernanceError, + spl_governance_tools::error::GovernanceToolsError, +}; #[tokio::test] async fn test_set_realm_authority() { diff --git a/governance/program/tests/process_set_realm_config.rs b/governance/program/tests/process_set_realm_config.rs index d87c19af46f..5db12e433d0 100644 --- a/governance/program/tests/process_set_realm_config.rs +++ b/governance/program/tests/process_set_realm_config.rs @@ -1,18 +1,18 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::*; -use spl_governance::{ - error::GovernanceError, - state::{realm::GoverningTokenConfigAccountArgs, realm_config::GoverningTokenType}, +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + spl_governance::{ + error::GovernanceError, + state::{realm::GoverningTokenConfigAccountArgs, realm_config::GoverningTokenType}, + }, }; -use crate::program_test::args::RealmSetupArgs; - #[tokio::test] async fn test_set_realm_config() { // Arrange diff --git a/governance/program/tests/process_sign_off_proposal.rs b/governance/program/tests/process_sign_off_proposal.rs index 1f4c3204628..bb934c07fd3 100644 --- a/governance/program/tests/process_sign_off_proposal.rs +++ b/governance/program/tests/process_sign_off_proposal.rs @@ -2,13 +2,14 @@ mod program_test; -use solana_program::pubkey::Pubkey; -use solana_program_test::tokio; - -use program_test::*; -use solana_sdk::signature::{Keypair, Signer}; -use spl_governance::{error::GovernanceError, state::enums::ProposalState}; -use spl_governance_tools::error::GovernanceToolsError; +use { + program_test::*, + solana_program::pubkey::Pubkey, + solana_program_test::tokio, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{error::GovernanceError, state::enums::ProposalState}, + spl_governance_tools::error::GovernanceToolsError, +}; #[tokio::test] async fn test_sign_off_proposal() { diff --git a/governance/program/tests/process_withdraw_governing_tokens.rs b/governance/program/tests/process_withdraw_governing_tokens.rs index 2e593b52c79..09bbd7e21d2 100644 --- a/governance/program/tests/process_withdraw_governing_tokens.rs +++ b/governance/program/tests/process_withdraw_governing_tokens.rs @@ -1,21 +1,25 @@ #![cfg(feature = "test-sbf")] -use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; -use solana_program_test::*; +use { + solana_program::{instruction::AccountMeta, pubkey::Pubkey}, + solana_program_test::*, +}; mod program_test; -use program_test::*; -use solana_sdk::signature::Signer; - -use spl_governance::{ - error::GovernanceError, - instruction::withdraw_governing_tokens, - state::{realm_config::GoverningTokenType, token_owner_record::get_token_owner_record_address}, +use { + crate::program_test::args::RealmSetupArgs, + program_test::*, + solana_sdk::signature::Signer, + spl_governance::{ + error::GovernanceError, + instruction::withdraw_governing_tokens, + state::{ + realm_config::GoverningTokenType, token_owner_record::get_token_owner_record_address, + }, + }, }; -use crate::program_test::args::RealmSetupArgs; - #[tokio::test] async fn test_withdraw_community_tokens() { // Arrange diff --git a/governance/program/tests/program_test/cookies.rs b/governance/program/tests/program_test/cookies.rs index 2cda808ac10..9c282abc66f 100644 --- a/governance/program/tests/program_test/cookies.rs +++ b/governance/program/tests/program_test/cookies.rs @@ -1,18 +1,19 @@ -use solana_program::{instruction::Instruction, pubkey::Pubkey}; -use solana_sdk::signature::Keypair; -use spl_governance::state::{ - governance::GovernanceV2, native_treasury::NativeTreasury, program_metadata::ProgramMetadata, - proposal::ProposalV2, proposal_deposit::ProposalDeposit, - proposal_transaction::ProposalTransactionV2, realm::RealmV2, realm_config::RealmConfigAccount, - signatory_record::SignatoryRecordV2, token_owner_record::TokenOwnerRecordV2, - vote_record::VoteRecordV2, +use { + solana_program::{instruction::Instruction, pubkey::Pubkey}, + solana_sdk::signature::Keypair, + spl_governance::state::{ + governance::GovernanceV2, native_treasury::NativeTreasury, + program_metadata::ProgramMetadata, proposal::ProposalV2, proposal_deposit::ProposalDeposit, + proposal_transaction::ProposalTransactionV2, realm::RealmV2, + realm_config::RealmConfigAccount, signatory_record::SignatoryRecordV2, + token_owner_record::TokenOwnerRecordV2, vote_record::VoteRecordV2, + }, + spl_governance_addin_api::{ + max_voter_weight::MaxVoterWeightRecord, voter_weight::VoterWeightRecord, + }, + spl_governance_test_sdk::tools::clone_keypair, }; -use spl_governance_addin_api::{ - max_voter_weight::MaxVoterWeightRecord, voter_weight::VoterWeightRecord, -}; -use spl_governance_test_sdk::tools::clone_keypair; - pub trait AccountCookie { fn get_address(&self) -> Pubkey; } diff --git a/governance/program/tests/program_test/legacy.rs b/governance/program/tests/program_test/legacy.rs index 5dac7868e4f..2de2e904e68 100644 --- a/governance/program/tests/program_test/legacy.rs +++ b/governance/program/tests/program_test/legacy.rs @@ -1,6 +1,8 @@ -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use solana_program::pubkey::Pubkey; -use spl_governance::state::{enums::GovernanceAccountType, governance::GovernanceV2}; +use { + borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, + solana_program::pubkey::Pubkey, + spl_governance::state::{enums::GovernanceAccountType, governance::GovernanceV2}, +}; /// Legacy Governance account as of spl-gov V1 #[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)] diff --git a/governance/program/tests/program_test/mod.rs b/governance/program/tests/program_test/mod.rs index 525668263bb..1b3bfad8609 100644 --- a/governance/program/tests/program_test/mod.rs +++ b/governance/program/tests/program_test/mod.rs @@ -1,103 +1,103 @@ #![allow(clippy::arithmetic_side_effects)] -use std::str::FromStr; - -use borsh::BorshSerialize; -use solana_program::{ - bpf_loader_upgradeable::{self, UpgradeableLoaderState}, - clock::{Slot, UnixTimestamp}, - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - program_pack::{IsInitialized, Pack}, - pubkey::Pubkey, - system_instruction, -}; - -use solana_program_test::*; - -use solana_sdk::signature::{Keypair, Signer}; - -use spl_governance::{ - instruction::{ - add_required_signatory, add_signatory, cancel_proposal, cast_vote, complete_proposal, - create_governance, create_mint_governance, create_native_treasury, - create_program_governance, create_proposal, create_realm, create_token_governance, - create_token_owner_record, deposit_governing_tokens, execute_transaction, finalize_vote, - flag_transaction_error, insert_transaction, refund_proposal_deposit, relinquish_vote, - remove_required_signatory, remove_transaction, revoke_governing_tokens, - set_governance_config, set_governance_delegate, set_realm_authority, set_realm_config, - sign_off_proposal, upgrade_program_metadata, withdraw_governing_tokens, - AddSignatoryAuthority, +use { + borsh::BorshSerialize, + solana_program::{ + bpf_loader_upgradeable::{self, UpgradeableLoaderState}, + clock::{Slot, UnixTimestamp}, + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + program_pack::{IsInitialized, Pack}, + pubkey::Pubkey, + system_instruction, }, - processor::process_instruction, - state::{ - enums::{ - GovernanceAccountType, InstructionExecutionFlags, MintMaxVoterWeightSource, - ProposalState, TransactionExecutionStatus, VoteThreshold, - }, - governance::{ - get_governance_address, get_mint_governance_address, get_program_governance_address, - get_token_governance_address, GovernanceConfig, GovernanceV2, - DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, + solana_program_test::*, + solana_sdk::signature::{Keypair, Signer}, + spl_governance::{ + instruction::{ + add_required_signatory, add_signatory, cancel_proposal, cast_vote, complete_proposal, + create_governance, create_mint_governance, create_native_treasury, + create_program_governance, create_proposal, create_realm, create_token_governance, + create_token_owner_record, deposit_governing_tokens, execute_transaction, + finalize_vote, flag_transaction_error, insert_transaction, refund_proposal_deposit, + relinquish_vote, remove_required_signatory, remove_transaction, + revoke_governing_tokens, set_governance_config, set_governance_delegate, + set_realm_authority, set_realm_config, sign_off_proposal, upgrade_program_metadata, + withdraw_governing_tokens, AddSignatoryAuthority, }, - native_treasury::{get_native_treasury_address, NativeTreasury}, - program_metadata::{get_program_metadata_address, ProgramMetadata}, - proposal::{get_proposal_address, OptionVoteResult, ProposalOption, ProposalV2, VoteType}, - proposal_deposit::{get_proposal_deposit_address, ProposalDeposit}, - proposal_transaction::{ - get_proposal_transaction_address, InstructionData, ProposalTransactionV2, - }, - realm::{ - get_governing_token_holding_address, get_realm_address, - GoverningTokenConfigAccountArgs, RealmConfig, RealmV2, SetRealmAuthorityAction, + processor::process_instruction, + state::{ + enums::{ + GovernanceAccountType, InstructionExecutionFlags, MintMaxVoterWeightSource, + ProposalState, TransactionExecutionStatus, VoteThreshold, + }, + governance::{ + get_governance_address, get_mint_governance_address, + get_program_governance_address, get_token_governance_address, GovernanceConfig, + GovernanceV2, DEFAULT_DEPOSIT_EXEMPT_PROPOSAL_COUNT, + }, + native_treasury::{get_native_treasury_address, NativeTreasury}, + program_metadata::{get_program_metadata_address, ProgramMetadata}, + proposal::{ + get_proposal_address, OptionVoteResult, ProposalOption, ProposalV2, VoteType, + }, + proposal_deposit::{get_proposal_deposit_address, ProposalDeposit}, + proposal_transaction::{ + get_proposal_transaction_address, InstructionData, ProposalTransactionV2, + }, + realm::{ + get_governing_token_holding_address, get_realm_address, + GoverningTokenConfigAccountArgs, RealmConfig, RealmV2, SetRealmAuthorityAction, + }, + realm_config::{get_realm_config_address, GoverningTokenConfig, RealmConfigAccount}, + required_signatory::RequiredSignatory, + signatory_record::{get_signatory_record_address, SignatoryRecordV2}, + token_owner_record::{ + get_token_owner_record_address, TokenOwnerRecordV2, + TOKEN_OWNER_RECORD_LAYOUT_VERSION, + }, + vote_record::{get_vote_record_address, Vote, VoteChoice, VoteRecordV2}, }, - realm_config::{get_realm_config_address, GoverningTokenConfig, RealmConfigAccount}, - required_signatory::RequiredSignatory, - signatory_record::{get_signatory_record_address, SignatoryRecordV2}, - token_owner_record::{ - get_token_owner_record_address, TokenOwnerRecordV2, TOKEN_OWNER_RECORD_LAYOUT_VERSION, + tools::{ + bpf_loader_upgradeable::get_program_data_address, + structs::{Reserved110, Reserved119}, }, - vote_record::{get_vote_record_address, Vote, VoteChoice, VoteRecordV2}, }, - tools::{ - bpf_loader_upgradeable::get_program_data_address, - structs::{Reserved110, Reserved119}, + spl_governance_addin_api::{ + max_voter_weight::MaxVoterWeightRecord, + voter_weight::{VoterWeightAction, VoterWeightRecord}, }, -}; -use spl_governance_addin_api::{ - max_voter_weight::MaxVoterWeightRecord, - voter_weight::{VoterWeightAction, VoterWeightRecord}, -}; -use spl_governance_addin_mock::instruction::{ - setup_max_voter_weight_record, setup_voter_weight_record, + spl_governance_addin_mock::instruction::{ + setup_max_voter_weight_record, setup_voter_weight_record, + }, + std::str::FromStr, }; pub mod args; pub mod cookies; pub mod legacy; -use crate::program_test::cookies::{ - RealmConfigCookie, SignatoryRecordCookie, VoterWeightRecordCookie, -}; - -use spl_governance_test_sdk::{ - addins::ensure_addin_mock_is_built, - cookies::WalletCookie, - tools::{clone_keypair, NopOverride}, - ProgramTestBench, -}; - -use crate::{ - args::{PluginSetupArgs, RealmSetupArgs}, - cookies::{ - GovernanceCookie, GovernedAccountCookie, GovernedMintCookie, GovernedProgramCookie, - GovernedTokenCookie, MaxVoterWeightRecordCookie, NativeTreasuryCookie, - ProgramMetadataCookie, ProposalCookie, ProposalTransactionCookie, RealmCookie, - TokenOwnerRecordCookie, VoteRecordCookie, +use { + self::cookies::ProposalDepositCookie, + crate::{ + args::{PluginSetupArgs, RealmSetupArgs}, + cookies::{ + GovernanceCookie, GovernedAccountCookie, GovernedMintCookie, GovernedProgramCookie, + GovernedTokenCookie, MaxVoterWeightRecordCookie, NativeTreasuryCookie, + ProgramMetadataCookie, ProposalCookie, ProposalTransactionCookie, RealmCookie, + TokenOwnerRecordCookie, VoteRecordCookie, + }, + program_test::cookies::{ + RealmConfigCookie, SignatoryRecordCookie, VoterWeightRecordCookie, + }, + }, + spl_governance_test_sdk::{ + addins::ensure_addin_mock_is_built, + cookies::WalletCookie, + tools::{clone_keypair, NopOverride}, + ProgramTestBench, }, }; -use self::cookies::ProposalDepositCookie; - /// Yes/No Vote pub enum YesNoVote { /// Yes vote diff --git a/governance/program/tests/setup_realm_with_all_addins.rs b/governance/program/tests/setup_realm_with_all_addins.rs index 5fe2c9bca9f..6502fcfd44c 100644 --- a/governance/program/tests/setup_realm_with_all_addins.rs +++ b/governance/program/tests/setup_realm_with_all_addins.rs @@ -1,13 +1,10 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::*; - -use crate::program_test::args::RealmSetupArgs; +use {crate::program_test::args::RealmSetupArgs, program_test::*}; #[tokio::test] async fn test_create_realm_with_all_addins() { diff --git a/governance/program/tests/setup_realm_with_max_voter_weight_addin.rs b/governance/program/tests/setup_realm_with_max_voter_weight_addin.rs index 47363bffc61..0b31c2ca5fc 100644 --- a/governance/program/tests/setup_realm_with_max_voter_weight_addin.rs +++ b/governance/program/tests/setup_realm_with_max_voter_weight_addin.rs @@ -1,13 +1,10 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::*; - -use crate::program_test::args::RealmSetupArgs; +use {crate::program_test::args::RealmSetupArgs, program_test::*}; #[tokio::test] async fn test_create_realm_with_max_voter_weight_addin() { diff --git a/governance/program/tests/setup_realm_with_voter_weight_addin.rs b/governance/program/tests/setup_realm_with_voter_weight_addin.rs index 2cd062c8d4c..00d0ca56733 100644 --- a/governance/program/tests/setup_realm_with_voter_weight_addin.rs +++ b/governance/program/tests/setup_realm_with_voter_weight_addin.rs @@ -1,12 +1,10 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use crate::program_test::args::RealmSetupArgs; -use program_test::*; +use {crate::program_test::args::RealmSetupArgs, program_test::*}; #[tokio::test] async fn test_create_realm_with_voter_weight_addin() { diff --git a/governance/program/tests/use_proposals_with_multiple_options.rs b/governance/program/tests/use_proposals_with_multiple_options.rs index 05da555becf..a7190ce8cbe 100644 --- a/governance/program/tests/use_proposals_with_multiple_options.rs +++ b/governance/program/tests/use_proposals_with_multiple_options.rs @@ -4,14 +4,15 @@ use solana_program_test::*; mod program_test; -use program_test::*; -use spl_governance::state::proposal::MultiChoiceType; -use spl_governance::{ - error::GovernanceError, - state::{ - enums::{ProposalState, VoteThreshold}, - proposal::{OptionVoteResult, VoteType}, - vote_record::{Vote, VoteChoice}, +use { + program_test::*, + spl_governance::{ + error::GovernanceError, + state::{ + enums::{ProposalState, VoteThreshold}, + proposal::{MultiChoiceType, OptionVoteResult, VoteType}, + vote_record::{Vote, VoteChoice}, + }, }, }; diff --git a/governance/program/tests/use_realm_with_all_addins.rs b/governance/program/tests/use_realm_with_all_addins.rs index 10c60073093..4149effceb2 100644 --- a/governance/program/tests/use_realm_with_all_addins.rs +++ b/governance/program/tests/use_realm_with_all_addins.rs @@ -4,9 +4,10 @@ use solana_program_test::*; mod program_test; -use program_test::args::*; -use program_test::*; -use spl_governance::state::enums::ProposalState; +use { + program_test::{args::*, *}, + spl_governance::state::enums::ProposalState, +}; #[tokio::test] async fn test_cast_community_vote_with_all_addin() { diff --git a/governance/program/tests/use_realm_with_max_voter_weight_addin.rs b/governance/program/tests/use_realm_with_max_voter_weight_addin.rs index 99a4f502382..1231d758b39 100644 --- a/governance/program/tests/use_realm_with_max_voter_weight_addin.rs +++ b/governance/program/tests/use_realm_with_max_voter_weight_addin.rs @@ -4,9 +4,10 @@ use solana_program_test::*; mod program_test; -use program_test::args::*; -use program_test::*; -use spl_governance::{error::GovernanceError, state::enums::ProposalState}; +use { + program_test::{args::*, *}, + spl_governance::{error::GovernanceError, state::enums::ProposalState}, +}; #[tokio::test] async fn test_cast_vote_with_community_max_voter_weight_addin() { diff --git a/governance/program/tests/use_realm_with_voter_weight_addin.rs b/governance/program/tests/use_realm_with_voter_weight_addin.rs index 370c9f5ee1e..342078cc5fc 100644 --- a/governance/program/tests/use_realm_with_voter_weight_addin.rs +++ b/governance/program/tests/use_realm_with_voter_weight_addin.rs @@ -1,18 +1,17 @@ #![cfg(feature = "test-sbf")] -use solana_program::pubkey::Pubkey; -use solana_program_test::*; +use {solana_program::pubkey::Pubkey, solana_program_test::*}; mod program_test; -use program_test::args::*; -use program_test::*; - -use spl_governance::{ - error::GovernanceError, - state::vote_record::{Vote, VoteChoice}, +use { + program_test::{args::*, *}, + spl_governance::{ + error::GovernanceError, + state::vote_record::{Vote, VoteChoice}, + }, + spl_governance_addin_api::voter_weight::VoterWeightAction, }; -use spl_governance_addin_api::voter_weight::VoterWeightAction; #[tokio::test] async fn test_create_governance_with_community_voter_weight_addin() { diff --git a/governance/program/tests/use_veto_vote.rs b/governance/program/tests/use_veto_vote.rs index 0f07af05345..2369f258752 100644 --- a/governance/program/tests/use_veto_vote.rs +++ b/governance/program/tests/use_veto_vote.rs @@ -1,21 +1,20 @@ #![cfg(feature = "test-sbf")] mod program_test; -use program_test::*; - -use solana_program::instruction::AccountMeta; -use solana_program_test::tokio; - -use spl_governance::{ - error::GovernanceError, - state::{ - enums::{ProposalState, VoteThreshold}, - vote_record::Vote, +use { + crate::program_test::args::{PluginSetupArgs, RealmSetupArgs}, + program_test::*, + solana_program::instruction::AccountMeta, + solana_program_test::tokio, + spl_governance::{ + error::GovernanceError, + state::{ + enums::{ProposalState, VoteThreshold}, + vote_record::Vote, + }, }, + spl_governance_test_sdk::tools::clone_keypair, }; -use spl_governance_test_sdk::tools::clone_keypair; - -use crate::program_test::args::{PluginSetupArgs, RealmSetupArgs}; #[tokio::test] async fn test_cast_council_veto_vote() { diff --git a/governance/test-sdk/src/addins.rs b/governance/test-sdk/src/addins.rs index 891b30ad830..101f1b3a95c 100644 --- a/governance/test-sdk/src/addins.rs +++ b/governance/test-sdk/src/addins.rs @@ -1,7 +1,8 @@ -use lazy_static::lazy_static; - -use solana_program_test::find_file; -use std::{process::Command, sync::Mutex}; +use { + lazy_static::lazy_static, + solana_program_test::find_file, + std::{process::Command, sync::Mutex}, +}; lazy_static! { pub static ref VOTER_WEIGHT_ADDIN_BUILD_GUARD: Mutex:: = Mutex::new(0); diff --git a/governance/test-sdk/src/cookies.rs b/governance/test-sdk/src/cookies.rs index 2f47c625b63..cd9e1bcd803 100644 --- a/governance/test-sdk/src/cookies.rs +++ b/governance/test-sdk/src/cookies.rs @@ -1,5 +1,4 @@ -use solana_program::pubkey::Pubkey; -use solana_sdk::account::Account; +use {solana_program::pubkey::Pubkey, solana_sdk::account::Account}; #[derive(Debug)] pub struct TokenAccountCookie { diff --git a/governance/test-sdk/src/lib.rs b/governance/test-sdk/src/lib.rs index 2587f4c55a4..76b9ba555ae 100644 --- a/governance/test-sdk/src/lib.rs +++ b/governance/test-sdk/src/lib.rs @@ -1,27 +1,25 @@ #![allow(clippy::arithmetic_side_effects)] -use std::borrow::Borrow; - -use borsh::{BorshDeserialize, BorshSerialize}; -use cookies::{TokenAccountCookie, WalletCookie}; -use solana_program::{ - borsh0_10::try_from_slice_unchecked, clock::Clock, instruction::Instruction, - program_error::ProgramError, program_pack::Pack, pubkey::Pubkey, rent::Rent, - stake_history::Epoch, system_instruction, system_program, sysvar, +use { + crate::tools::map_transaction_error, + bincode::deserialize, + borsh::{BorshDeserialize, BorshSerialize}, + cookies::{TokenAccountCookie, WalletCookie}, + solana_program::{ + borsh0_10::try_from_slice_unchecked, clock::Clock, instruction::Instruction, + program_error::ProgramError, program_pack::Pack, pubkey::Pubkey, rent::Rent, + stake_history::Epoch, system_instruction, system_program, sysvar, + }, + solana_program_test::{ProgramTest, ProgramTestContext}, + solana_sdk::{ + account::{Account, AccountSharedData, WritableAccount}, + signature::Keypair, + signer::Signer, + transaction::Transaction, + }, + spl_token::instruction::{set_authority, AuthorityType}, + std::borrow::Borrow, + tools::clone_keypair, }; -use solana_program_test::{ProgramTest, ProgramTestContext}; -use solana_sdk::{ - account::{Account, AccountSharedData, WritableAccount}, - signature::Keypair, - signer::Signer, - transaction::Transaction, -}; - -use bincode::deserialize; - -use spl_token::instruction::{set_authority, AuthorityType}; -use tools::clone_keypair; - -use crate::tools::map_transaction_error; pub mod addins; pub mod cookies; diff --git a/governance/test-sdk/src/tools.rs b/governance/test-sdk/src/tools.rs index b1b6538431e..8705f8fb9ca 100644 --- a/governance/test-sdk/src/tools.rs +++ b/governance/test-sdk/src/tools.rs @@ -1,7 +1,8 @@ -use std::convert::TryFrom; - -use solana_program::{instruction::InstructionError, program_error::ProgramError}; -use solana_sdk::{signature::Keypair, transaction::TransactionError, transport::TransportError}; +use { + solana_program::{instruction::InstructionError, program_error::ProgramError}, + solana_sdk::{signature::Keypair, transaction::TransactionError, transport::TransportError}, + std::convert::TryFrom, +}; /// TODO: Add to Solana SDK /// Instruction errors not mapped in the sdk diff --git a/governance/tools/src/account.rs b/governance/tools/src/account.rs index a5e267b241b..cd29fbf8c9d 100644 --- a/governance/tools/src/account.rs +++ b/governance/tools/src/account.rs @@ -1,23 +1,23 @@ //! General purpose account utility functions -use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::{ - account_info::AccountInfo, - borsh0_10::try_from_slice_unchecked, - msg, - program::invoke, - program::invoke_signed, - program_error::ProgramError, - program_pack::IsInitialized, - pubkey::Pubkey, - rent::Rent, - system_instruction::{self, create_account}, - system_program, - sysvar::Sysvar, +use { + crate::error::GovernanceToolsError, + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::{ + account_info::AccountInfo, + borsh0_10::try_from_slice_unchecked, + msg, + program::{invoke, invoke_signed}, + program_error::ProgramError, + program_pack::IsInitialized, + pubkey::Pubkey, + rent::Rent, + system_instruction::{self, create_account}, + system_program, + sysvar::Sysvar, + }, }; -use crate::error::GovernanceToolsError; - /// Trait for accounts to return their max size pub trait AccountMaxSize { /// Returns max account size or None if max size is not known and actual instance size should be used diff --git a/governance/tools/src/error.rs b/governance/tools/src/error.rs index c4fe2f57702..feb84ec9bbf 100644 --- a/governance/tools/src/error.rs +++ b/governance/tools/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the GovernanceTools #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/libraries/concurrent-merkle-tree/src/concurrent_merkle_tree.rs b/libraries/concurrent-merkle-tree/src/concurrent_merkle_tree.rs index ea75537284d..6e619b835af 100644 --- a/libraries/concurrent-merkle-tree/src/concurrent_merkle_tree.rs +++ b/libraries/concurrent-merkle-tree/src/concurrent_merkle_tree.rs @@ -1,13 +1,14 @@ -use crate::{ - changelog::ChangeLog, - error::ConcurrentMerkleTreeError, - hash::{fill_in_proof, hash_to_parent, recompute}, - node::{empty_node, empty_node_cached, Node, EMPTY}, - path::Path, +use { + crate::{ + changelog::ChangeLog, + error::ConcurrentMerkleTreeError, + hash::{fill_in_proof, hash_to_parent, recompute}, + node::{empty_node, empty_node_cached, Node, EMPTY}, + path::Path, + }, + bytemuck::{Pod, Zeroable}, + log_compute, solana_logging, }; -use bytemuck::{Pod, Zeroable}; -use log_compute; -use solana_logging; /// Enforce constraints on max depth and buffer size #[inline(always)] diff --git a/libraries/concurrent-merkle-tree/src/hash.rs b/libraries/concurrent-merkle-tree/src/hash.rs index 04eb4a9c8ab..887618eb07c 100644 --- a/libraries/concurrent-merkle-tree/src/hash.rs +++ b/libraries/concurrent-merkle-tree/src/hash.rs @@ -1,5 +1,7 @@ -use crate::node::{empty_node, Node}; -use solana_program::keccak::hashv; +use { + crate::node::{empty_node, Node}, + solana_program::keccak::hashv, +}; /// Recomputes root of the Merkle tree from Node & proof pub fn recompute(leaf: Node, proof: &[Node], index: u32) -> Node { diff --git a/libraries/concurrent-merkle-tree/tests/tests.rs b/libraries/concurrent-merkle-tree/tests/tests.rs index e1f2aa5248f..3138d5bbec0 100644 --- a/libraries/concurrent-merkle-tree/tests/tests.rs +++ b/libraries/concurrent-merkle-tree/tests/tests.rs @@ -1,10 +1,13 @@ #![allow(clippy::arithmetic_side_effects)] -use rand::thread_rng; -use rand::{self, Rng}; -use spl_concurrent_merkle_tree::concurrent_merkle_tree::ConcurrentMerkleTree; -use spl_concurrent_merkle_tree::error::ConcurrentMerkleTreeError; -use spl_concurrent_merkle_tree::node::{Node, EMPTY}; -use spl_merkle_tree_reference::MerkleTree; +use { + rand::{self, thread_rng, Rng}, + spl_concurrent_merkle_tree::{ + concurrent_merkle_tree::ConcurrentMerkleTree, + error::ConcurrentMerkleTreeError, + node::{Node, EMPTY}, + }, + spl_merkle_tree_reference::MerkleTree, +}; const DEPTH: usize = 10; const BUFFER_SIZE: usize = 64; diff --git a/libraries/math/src/error.rs b/libraries/math/src/error.rs index 5667e519056..301bf7740c2 100644 --- a/libraries/math/src/error.rs +++ b/libraries/math/src/error.rs @@ -29,8 +29,7 @@ impl DecodeError for MathError { #[cfg(test)] mod tests { - use super::*; - use solana_program::program_error::ProgramError; + use {super::*, solana_program::program_error::ProgramError}; #[test] fn test_math_error_from() { diff --git a/libraries/math/src/precise_number.rs b/libraries/math/src/precise_number.rs index cf2c1eeb8de..c58d248e92c 100644 --- a/libraries/math/src/precise_number.rs +++ b/libraries/math/src/precise_number.rs @@ -366,8 +366,7 @@ impl PreciseNumber { #[cfg(test)] mod tests { - use super::*; - use proptest::prelude::*; + use {super::*, proptest::prelude::*}; fn check_pow_approximation(base: InnerUint, exponent: InnerUint, expected: InnerUint) { let precision = InnerUint::from(5_000_000); // correct to at least 3 decimal places diff --git a/libraries/math/src/processor.rs b/libraries/math/src/processor.rs index ebdd2823a53..45c1cbd26d7 100644 --- a/libraries/math/src/processor.rs +++ b/libraries/math/src/processor.rs @@ -167,9 +167,7 @@ pub fn process_instruction( #[cfg(test)] mod tests { - use super::*; - use crate::instruction::MathInstruction; - use borsh::BorshSerialize; + use {super::*, crate::instruction::MathInstruction, borsh::BorshSerialize}; #[test] fn test_u64_multiply() { diff --git a/libraries/merkle-tree-reference/src/lib.rs b/libraries/merkle-tree-reference/src/lib.rs index 0828517b574..548e9c20cb5 100644 --- a/libraries/merkle-tree-reference/src/lib.rs +++ b/libraries/merkle-tree-reference/src/lib.rs @@ -1,9 +1,8 @@ #![allow(clippy::arithmetic_side_effects)] -use solana_program::keccak::hashv; -use std::cell::RefCell; -use std::collections::VecDeque; -use std::iter::FromIterator; -use std::rc::Rc; +use { + solana_program::keccak::hashv, + std::{cell::RefCell, collections::VecDeque, iter::FromIterator, rc::Rc}, +}; pub type Node = [u8; 32]; pub const EMPTY: Node = [0; 32]; diff --git a/libraries/pod/src/optional_keys.rs b/libraries/pod/src/optional_keys.rs index 3622929615f..34bb75e5254 100644 --- a/libraries/pod/src/optional_keys.rs +++ b/libraries/pod/src/optional_keys.rs @@ -1,10 +1,6 @@ //! Optional pubkeys that can be used a `Pod`s -use { - bytemuck::{Pod, Zeroable}, - solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey}, - solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalPubkey, -}; - +#[cfg(feature = "borsh")] +use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; #[cfg(feature = "serde-traits")] use { base64::{prelude::BASE64_STANDARD, Engine}, @@ -12,9 +8,11 @@ use { serde::{Deserialize, Deserializer, Serialize, Serializer}, std::{convert::TryFrom, fmt, str::FromStr}, }; - -#[cfg(feature = "borsh")] -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use { + bytemuck::{Pod, Zeroable}, + solana_program::{program_error::ProgramError, program_option::COption, pubkey::Pubkey}, + solana_zk_token_sdk::zk_token_elgamal::pod::ElGamalPubkey, +}; /// A Pubkey that encodes `None` as all `0`, meant to be usable as a Pod type, similar to all /// NonZero* number types from the bytemuck library. diff --git a/libraries/pod/src/primitives.rs b/libraries/pod/src/primitives.rs index 636d48afdfa..9cb8d85206d 100644 --- a/libraries/pod/src/primitives.rs +++ b/libraries/pod/src/primitives.rs @@ -1,12 +1,10 @@ //! primitive types that can be used in `Pod`s +#[cfg(feature = "borsh")] +use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use bytemuck::{Pod, Zeroable}; - #[cfg(feature = "serde-traits")] use serde::{Deserialize, Serialize}; -#[cfg(feature = "borsh")] -use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; - /// The standard `bool` is not a `Pod`, define a replacement that is #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(from = "bool", into = "bool"))] diff --git a/managed-token/program/src/accounts.rs b/managed-token/program/src/accounts.rs index dbc7a711b83..01bc6b44f7f 100644 --- a/managed-token/program/src/accounts.rs +++ b/managed-token/program/src/accounts.rs @@ -1,8 +1,10 @@ -use crate::assert_with_msg; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - program_error::ProgramError, - system_program, +use { + crate::assert_with_msg, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + program_error::ProgramError, + system_program, + }, }; pub struct InitializeMint<'a, 'info> { diff --git a/managed-token/program/src/instruction.rs b/managed-token/program/src/instruction.rs index 7fb85339ab2..c3801690aa0 100644 --- a/managed-token/program/src/instruction.rs +++ b/managed-token/program/src/instruction.rs @@ -1,14 +1,15 @@ -use borsh::{BorshDeserialize, BorshSerialize}; -use shank::ShankInstruction; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - pubkey::Pubkey, - system_program, +use { + crate::get_authority, + borsh::{BorshDeserialize, BorshSerialize}, + shank::ShankInstruction, + solana_program::{ + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + pubkey::Pubkey, + system_program, + }, + spl_associated_token_account::get_associated_token_address, }; -use spl_associated_token_account::get_associated_token_address; - -use crate::get_authority; #[derive(Debug, Clone, ShankInstruction, BorshSerialize, BorshDeserialize)] #[rustfmt::skip] diff --git a/managed-token/program/src/lib.rs b/managed-token/program/src/lib.rs index 4b4061356ca..389694ec363 100644 --- a/managed-token/program/src/lib.rs +++ b/managed-token/program/src/lib.rs @@ -1,12 +1,14 @@ solana_program::declare_id!("mTok58Lg4YfcmwqyrDHpf7ogp599WRhzb6PxjaBqAxS"); -use borsh::BorshDeserialize; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, msg, program::invoke, - program_error::ProgramError, program_pack::Pack, pubkey::Pubkey, rent::Rent, - system_instruction, sysvar::Sysvar, +use { + borsh::BorshDeserialize, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, msg, program::invoke, + program_error::ProgramError, program_pack::Pack, pubkey::Pubkey, rent::Rent, + system_instruction, sysvar::Sysvar, + }, + spl_associated_token_account::instruction::create_associated_token_account, }; -use spl_associated_token_account::instruction::create_associated_token_account; #[track_caller] #[inline(always)] @@ -23,9 +25,11 @@ pub fn assert_with_msg(v: bool, err: impl Into, msg: &str) -> Prog pub mod accounts; pub mod instruction; pub mod token; -use accounts::{Approve, Burn, Close, InitializeAccount, InitializeMint, Mint, Revoke, Transfer}; -use instruction::ManagedTokenInstruction; -use token::{approve, burn, close, freeze, initialize_mint, mint_to, revoke, thaw, transfer}; +use { + accounts::{Approve, Burn, Close, InitializeAccount, InitializeMint, Mint, Revoke, Transfer}, + instruction::ManagedTokenInstruction, + token::{approve, burn, close, freeze, initialize_mint, mint_to, revoke, thaw, transfer}, +}; #[cfg(not(feature = "no-entrypoint"))] solana_program::entrypoint!(process_instruction); diff --git a/managed-token/program/tests/test.rs b/managed-token/program/tests/test.rs index b3c46ba5164..7ddaf49ca09 100644 --- a/managed-token/program/tests/test.rs +++ b/managed-token/program/tests/test.rs @@ -1,22 +1,22 @@ -use solana_program::program_option::COption; -use solana_program_test::*; -use solana_sdk::{ - commitment_config::CommitmentLevel, - instruction::Instruction, - native_token::LAMPORTS_PER_SOL, - pubkey::Pubkey, - signature::Signature, - signature::{Keypair, Signer}, - system_instruction, - transaction::Transaction, +use { + solana_program::program_option::COption, + solana_program_test::*, + solana_sdk::{ + commitment_config::CommitmentLevel, + instruction::Instruction, + native_token::LAMPORTS_PER_SOL, + pubkey::Pubkey, + signature::{Keypair, Signature, Signer}, + system_instruction, + transaction::Transaction, + }, + spl_associated_token_account::{ + get_associated_token_address, instruction::create_associated_token_account, + }, + spl_managed_token::instruction::*, + spl_token::state::Account as TokenAccount, }; -use spl_associated_token_account::{ - get_associated_token_address, instruction::create_associated_token_account, -}; -use spl_managed_token::instruction::*; -use spl_token::state::Account as TokenAccount; - pub fn sol(amount: f64) -> u64 { (amount * LAMPORTS_PER_SOL as f64) as u64 } diff --git a/memo/program/src/processor.rs b/memo/program/src/processor.rs index f815c09b5da..57ca6ba382a 100644 --- a/memo/program/src/processor.rs +++ b/memo/program/src/processor.rs @@ -1,10 +1,12 @@ //! Program state processor -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError, - pubkey::Pubkey, +use { + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError, + pubkey::Pubkey, + }, + std::str::from_utf8, }; -use std::str::from_utf8; /// Instruction processor pub fn process_instruction( @@ -36,11 +38,13 @@ pub fn process_instruction( #[cfg(test)] mod tests { - use super::*; - use solana_program::{ - account_info::IntoAccountInfo, program_error::ProgramError, pubkey::Pubkey, + use { + super::*, + solana_program::{ + account_info::IntoAccountInfo, program_error::ProgramError, pubkey::Pubkey, + }, + solana_sdk::account::Account, }; - use solana_sdk::account::Account; #[test] fn test_utf8_memo() { diff --git a/memo/program/tests/functional.rs b/memo/program/tests/functional.rs index befbe56a0f1..763f639ff12 100644 --- a/memo/program/tests/functional.rs +++ b/memo/program/tests/functional.rs @@ -1,15 +1,17 @@ #![cfg(feature = "test-sbf")] -use solana_program::{ - instruction::{AccountMeta, Instruction, InstructionError}, - pubkey::Pubkey, +use { + solana_program::{ + instruction::{AccountMeta, Instruction, InstructionError}, + pubkey::Pubkey, + }, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_memo::*, }; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_memo::*; fn program_test() -> ProgramTest { ProgramTest::new("spl_memo", id(), processor!(processor::process_instruction)) diff --git a/name-service/program/src/entrypoint.rs b/name-service/program/src/entrypoint.rs index 5f4bac3bbe0..bd19cbdf4dd 100644 --- a/name-service/program/src/entrypoint.rs +++ b/name-service/program/src/entrypoint.rs @@ -1,6 +1,5 @@ use { - crate::error::NameServiceError, - crate::processor::Processor, + crate::{error::NameServiceError, processor::Processor}, num_traits::FromPrimitive, solana_program::{ account_info::AccountInfo, decode_error::DecodeError, entrypoint::ProgramResult, msg, diff --git a/name-service/program/src/processor.rs b/name-service/program/src/processor.rs index 80bec1faea2..f2533325a58 100644 --- a/name-service/program/src/processor.rs +++ b/name-service/program/src/processor.rs @@ -1,8 +1,7 @@ use { crate::{ instruction::NameRegistryInstruction, - state::get_seeds_and_key, - state::{write_data, NameRecordHeader}, + state::{get_seeds_and_key, write_data, NameRecordHeader}, }, borsh::BorshDeserialize, solana_program::{ diff --git a/name-service/program/tests/functional.rs b/name-service/program/tests/functional.rs index 23ecdad016f..c77415d6613 100644 --- a/name-service/program/tests/functional.rs +++ b/name-service/program/tests/functional.rs @@ -1,21 +1,20 @@ #![cfg(feature = "test-sbf")] -use std::str::FromStr; - -use solana_program::{instruction::Instruction, program_pack::Pack, pubkey::Pubkey}; -use solana_program_test::{ - processor, tokio, ProgramTest, ProgramTestBanksClientExt, ProgramTestContext, -}; - -use solana_program::hash::hashv; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, - transport::TransportError, -}; -use spl_name_service::{ - instruction::{create, delete, realloc, transfer, update, NameRegistryInstruction}, - processor::Processor, - state::{get_seeds_and_key, NameRecordHeader, HASH_PREFIX}, +use { + solana_program::{hash::hashv, instruction::Instruction, program_pack::Pack, pubkey::Pubkey}, + solana_program_test::{ + processor, tokio, ProgramTest, ProgramTestBanksClientExt, ProgramTestContext, + }, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + transport::TransportError, + }, + spl_name_service::{ + instruction::{create, delete, realloc, transfer, update, NameRegistryInstruction}, + processor::Processor, + state::{get_seeds_and_key, NameRecordHeader, HASH_PREFIX}, + }, + std::str::FromStr, }; #[tokio::test] diff --git a/record/program/src/error.rs b/record/program/src/error.rs index 537639154b7..d52354a89ff 100644 --- a/record/program/src/error.rs +++ b/record/program/src/error.rs @@ -1,8 +1,10 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{decode_error::DecodeError, program_error::ProgramError}; -use thiserror::Error; +use { + num_derive::FromPrimitive, + solana_program::{decode_error::DecodeError, program_error::ProgramError}, + thiserror::Error, +}; /// Errors that may be returned by the program. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/record/program/src/instruction.rs b/record/program/src/instruction.rs index bd86bd7183f..008af83e2bc 100644 --- a/record/program/src/instruction.rs +++ b/record/program/src/instruction.rs @@ -1,10 +1,12 @@ //! Program instructions -use crate::id; -use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, +use { + crate::id, + borsh::{BorshDeserialize, BorshSerialize}, + solana_program::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + }, }; /// Instructions supported by the program @@ -106,9 +108,7 @@ pub fn close_account(record_account: &Pubkey, signer: &Pubkey, receiver: &Pubkey #[cfg(test)] mod tests { - use super::*; - use crate::state::tests::TEST_DATA; - use solana_program::program_error::ProgramError; + use {super::*, crate::state::tests::TEST_DATA, solana_program::program_error::ProgramError}; #[test] fn serialize_initialize() { diff --git a/record/program/src/state.rs b/record/program/src/state.rs index cdf8fde8864..b88b698255f 100644 --- a/record/program/src/state.rs +++ b/record/program/src/state.rs @@ -46,8 +46,7 @@ impl IsInitialized for RecordData { #[cfg(test)] pub mod tests { - use super::*; - use solana_program::program_error::ProgramError; + use {super::*, solana_program::program_error::ProgramError}; /// Version for tests pub const TEST_VERSION: u8 = 1; diff --git a/rustfmt.toml b/rustfmt.toml index 36c419bb3e5..01593a5cb47 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,3 @@ -edition = "2021" \ No newline at end of file +edition = "2021" +group_imports = "One" +imports_granularity = "One" diff --git a/shared-memory/program/src/lib.rs b/shared-memory/program/src/lib.rs index 6003a5d24ac..ab4d075d619 100644 --- a/shared-memory/program/src/lib.rs +++ b/shared-memory/program/src/lib.rs @@ -8,15 +8,19 @@ // implement the typical `process_instruction` entrypoint. extern crate solana_program; -use arrayref::{array_refs, mut_array_refs}; -use solana_program::{ - declare_id, entrypoint::MAX_PERMITTED_DATA_INCREASE, entrypoint::SUCCESS, - program_error::ProgramError, pubkey::Pubkey, -}; -use std::{ - mem::{align_of, size_of}, - ptr::read, - slice::{from_raw_parts, from_raw_parts_mut}, +use { + arrayref::{array_refs, mut_array_refs}, + solana_program::{ + declare_id, + entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS}, + program_error::ProgramError, + pubkey::Pubkey, + }, + std::{ + mem::{align_of, size_of}, + ptr::read, + slice::{from_raw_parts, from_raw_parts_mut}, + }, }; declare_id!("shmem4EWT2sPdVGvTZCzXXRAURL9G5vpPxNwSeKhHUL"); diff --git a/shared-memory/program/tests/shared-memory.rs b/shared-memory/program/tests/shared-memory.rs index 94a4a430c2b..dd5c18b0ac3 100644 --- a/shared-memory/program/tests/shared-memory.rs +++ b/shared-memory/program/tests/shared-memory.rs @@ -1,14 +1,15 @@ // Program test does not support calling a raw program entrypoint, only `process_instruction` #![cfg(feature = "test-sbf")] -use solana_program_test::*; -use solana_sdk::{ - account::Account, - instruction::InstructionError, - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - signature::Signer, - transaction::{Transaction, TransactionError}, +use { + solana_program_test::*, + solana_sdk::{ + account::Account, + instruction::{AccountMeta, Instruction, InstructionError}, + pubkey::Pubkey, + signature::Signer, + transaction::{Transaction, TransactionError}, + }, }; #[tokio::test] diff --git a/single-pool/cli/src/config.rs b/single-pool/cli/src/config.rs index ca42dcf0e75..649c2c7ea17 100644 --- a/single-pool/cli/src/config.rs +++ b/single-pool/cli/src/config.rs @@ -1,4 +1,5 @@ use { + crate::cli::*, clap::ArgMatches, solana_clap_v3_utils::keypair::signer_from_path, solana_cli_output::OutputFormat, @@ -9,8 +10,6 @@ use { std::{process::exit, rc::Rc, sync::Arc}, }; -use crate::cli::*; - pub type Error = Box; pub fn println_display(config: &Config, message: String) { diff --git a/single-pool/cli/src/main.rs b/single-pool/cli/src/main.rs index c46fa2fe77a..9258947cf44 100644 --- a/single-pool/cli/src/main.rs +++ b/single-pool/cli/src/main.rs @@ -11,8 +11,7 @@ use { solana_sdk::{ borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, - signature::Signature, - signature::{Keypair, Signer}, + signature::{Keypair, Signature, Signer}, stake, transaction::Transaction, }, diff --git a/single-pool/cli/src/quarantine.rs b/single-pool/cli/src/quarantine.rs index 3e79f1ca12b..1b44a61d490 100644 --- a/single-pool/cli/src/quarantine.rs +++ b/single-pool/cli/src/quarantine.rs @@ -1,19 +1,20 @@ // XXX this file will be deleted and replaced with a stake program client once i write one -use solana_sdk::{ - instruction::Instruction, - native_token::LAMPORTS_PER_SOL, - pubkey::Pubkey, - stake::{ - self, - state::{Meta, Stake, StakeStateV2}, +use { + crate::config::*, + solana_sdk::{ + instruction::Instruction, + native_token::LAMPORTS_PER_SOL, + pubkey::Pubkey, + stake::{ + self, + state::{Meta, Stake, StakeStateV2}, + }, + system_instruction, + sysvar::{self, rent::Rent}, }, - system_instruction, - sysvar::{self, rent::Rent}, }; -use crate::config::*; - pub async fn get_rent(config: &Config) -> Result { let rent_data = config .program_client diff --git a/stake-pool/cli/src/main.rs b/stake-pool/cli/src/main.rs index 0edaafbc1bf..bc3b443fd5d 100644 --- a/stake-pool/cli/src/main.rs +++ b/stake-pool/cli/src/main.rs @@ -2,6 +2,9 @@ mod client; mod output; +// use instruction::create_associated_token_account once ATA 1.0.5 is released +#[allow(deprecated)] +use spl_associated_token_account::create_associated_token_account; use { crate::{ client::*, @@ -41,21 +44,16 @@ use { transaction::Transaction, }, spl_associated_token_account::get_associated_token_address, - spl_stake_pool::state::ValidatorStakeInfo, spl_stake_pool::{ self, find_stake_program_address, find_transient_stake_program_address, find_withdraw_authority_program_address, instruction::{FundingType, PreferredValidatorType}, minimum_delegation, - state::{Fee, FeeType, StakePool, ValidatorList}, + state::{Fee, FeeType, StakePool, ValidatorList, ValidatorStakeInfo}, MINIMUM_RESERVE_LAMPORTS, }, - std::cmp::Ordering, - std::{num::NonZeroU32, process::exit, rc::Rc}, + std::{cmp::Ordering, num::NonZeroU32, process::exit, rc::Rc}, }; -// use instruction::create_associated_token_account once ATA 1.0.5 is released -#[allow(deprecated)] -use spl_associated_token_account::create_associated_token_account; pub(crate) struct Config { rpc_client: RpcClient, diff --git a/stake-pool/cli/src/output.rs b/stake-pool/cli/src/output.rs index f1305245628..5eeb81bcdbd 100644 --- a/stake-pool/cli/src/output.rs +++ b/stake-pool/cli/src/output.rs @@ -1,8 +1,7 @@ use { serde::{Deserialize, Serialize}, solana_cli_output::{QuietDisplay, VerboseDisplay}, - solana_sdk::native_token::Sol, - solana_sdk::{pubkey::Pubkey, stake::state::Lockup}, + solana_sdk::{native_token::Sol, pubkey::Pubkey, stake::state::Lockup}, spl_stake_pool::state::{ Fee, PodStakeStatus, StakePool, StakeStatus, ValidatorList, ValidatorStakeInfo, }, diff --git a/stateless-asks/program/src/entrypoint.rs b/stateless-asks/program/src/entrypoint.rs index 57a98a463b8..cbf8ed562f9 100644 --- a/stateless-asks/program/src/entrypoint.rs +++ b/stateless-asks/program/src/entrypoint.rs @@ -1,8 +1,9 @@ #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; - -use crate::processor::Processor; +use { + crate::processor::Processor, + solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, +}; solana_program::entrypoint!(process_instruction); fn process_instruction( diff --git a/stateless-asks/program/src/error.rs b/stateless-asks/program/src/error.rs index ef35e575c3c..cc97352949f 100644 --- a/stateless-asks/program/src/error.rs +++ b/stateless-asks/program/src/error.rs @@ -1,6 +1,4 @@ -use thiserror::Error; - -use solana_program::program_error::ProgramError; +use {solana_program::program_error::ProgramError, thiserror::Error}; #[derive(Error, Debug, Copy, Clone)] pub enum UtilError { diff --git a/stateless-asks/program/src/processor.rs b/stateless-asks/program/src/processor.rs index 374a060505c..2ab98d02fbf 100644 --- a/stateless-asks/program/src/processor.rs +++ b/stateless-asks/program/src/processor.rs @@ -8,8 +8,7 @@ use { }, borsh::BorshDeserialize, solana_program::{ - account_info::next_account_info, - account_info::AccountInfo, + account_info::{next_account_info, AccountInfo}, borsh0_10::try_from_slice_unchecked, entrypoint::ProgramResult, msg, diff --git a/stateless-asks/program/src/validation_utils.rs b/stateless-asks/program/src/validation_utils.rs index 05112e480c0..6014693672d 100644 --- a/stateless-asks/program/src/validation_utils.rs +++ b/stateless-asks/program/src/validation_utils.rs @@ -1,14 +1,15 @@ -use super::error::UtilError; -use solana_program::{ - account_info::AccountInfo, - entrypoint::ProgramResult, - program_error::ProgramError, - program_pack::{IsInitialized, Pack}, - pubkey::Pubkey, +use { + super::error::UtilError, + solana_program::{ + account_info::AccountInfo, + entrypoint::ProgramResult, + program_error::ProgramError, + program_pack::{IsInitialized, Pack}, + pubkey::Pubkey, + }, + spl_associated_token_account::get_associated_token_address, + spl_token::{self, state::Account}, }; -use spl_associated_token_account::get_associated_token_address; -use spl_token; -use spl_token::state::Account; pub fn assert_is_ata(ata: &AccountInfo, wallet: &Pubkey, mint: &Pubkey) -> ProgramResult { assert_owned_by(ata, &spl_token::id())?; diff --git a/token-lending/flash_loan_receiver/src/processor.rs b/token-lending/flash_loan_receiver/src/processor.rs index 5908632d897..8d895e8aa98 100644 --- a/token-lending/flash_loan_receiver/src/processor.rs +++ b/token-lending/flash_loan_receiver/src/processor.rs @@ -1,12 +1,13 @@ -use std::convert::TryInto; - -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - msg, - program::invoke, - program_error::ProgramError, - pubkey::Pubkey, +use { + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + msg, + program::invoke, + program_error::ProgramError, + pubkey::Pubkey, + }, + std::convert::TryInto, }; pub fn process_instruction( diff --git a/token-lending/program/src/entrypoint.rs b/token-lending/program/src/entrypoint.rs index beba09dfad8..a0a78a9d4a0 100644 --- a/token-lending/program/src/entrypoint.rs +++ b/token-lending/program/src/entrypoint.rs @@ -2,10 +2,12 @@ #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] -use crate::{error::LendingError, processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::LendingError, processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/token-lending/program/src/error.rs b/token-lending/program/src/error.rs index 23da1977675..3503ea98a01 100644 --- a/token-lending/program/src/error.rs +++ b/token-lending/program/src/error.rs @@ -1,8 +1,10 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{decode_error::DecodeError, program_error::ProgramError}; -use thiserror::Error; +use { + num_derive::FromPrimitive, + solana_program::{decode_error::DecodeError, program_error::ProgramError}, + thiserror::Error, +}; /// Errors that may be returned by the TokenLending program. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/token-lending/program/src/instruction.rs b/token-lending/program/src/instruction.rs index 274f4b322f3..8bf938afe94 100644 --- a/token-lending/program/src/instruction.rs +++ b/token-lending/program/src/instruction.rs @@ -1,17 +1,19 @@ //! Instruction types -use crate::{ - error::LendingError, - state::{ReserveConfig, ReserveFees}, -}; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - msg, - program_error::ProgramError, - pubkey::{Pubkey, PUBKEY_BYTES}, - sysvar, +use { + crate::{ + error::LendingError, + state::{ReserveConfig, ReserveFees}, + }, + solana_program::{ + instruction::{AccountMeta, Instruction}, + msg, + program_error::ProgramError, + pubkey::{Pubkey, PUBKEY_BYTES}, + sysvar, + }, + std::{convert::TryInto, mem::size_of}, }; -use std::{convert::TryInto, mem::size_of}; /// Instructions supported by the lending program. #[derive(Clone, Debug, PartialEq)] diff --git a/token-lending/program/src/math/decimal.rs b/token-lending/program/src/math/decimal.rs index 8cc3fc8baa9..8e835b15981 100644 --- a/token-lending/program/src/math/decimal.rs +++ b/token-lending/program/src/math/decimal.rs @@ -12,13 +12,15 @@ #![allow(clippy::ptr_offset_with_cast)] #![allow(clippy::manual_range_contains)] -use crate::{ - error::LendingError, - math::{common::*, Rate}, +use { + crate::{ + error::LendingError, + math::{common::*, Rate}, + }, + solana_program::program_error::ProgramError, + std::{convert::TryFrom, fmt}, + uint::construct_uint, }; -use solana_program::program_error::ProgramError; -use std::{convert::TryFrom, fmt}; -use uint::construct_uint; // U192 with 192 bits consisting of 3 x 64-bit words construct_uint! { diff --git a/token-lending/program/src/math/mod.rs b/token-lending/program/src/math/mod.rs index 42744272f03..836a2f39c1a 100644 --- a/token-lending/program/src/math/mod.rs +++ b/token-lending/program/src/math/mod.rs @@ -4,6 +4,4 @@ mod common; mod decimal; mod rate; -pub use common::*; -pub use decimal::*; -pub use rate::*; +pub use {common::*, decimal::*, rate::*}; diff --git a/token-lending/program/src/math/rate.rs b/token-lending/program/src/math/rate.rs index c404c8ff2b8..166b6d5bf9f 100644 --- a/token-lending/program/src/math/rate.rs +++ b/token-lending/program/src/math/rate.rs @@ -18,13 +18,15 @@ #![allow(clippy::reversed_empty_ranges)] #![allow(clippy::manual_range_contains)] -use crate::{ - error::LendingError, - math::{common::*, decimal::Decimal}, +use { + crate::{ + error::LendingError, + math::{common::*, decimal::Decimal}, + }, + solana_program::program_error::ProgramError, + std::{convert::TryFrom, fmt}, + uint::construct_uint, }; -use solana_program::program_error::ProgramError; -use std::{convert::TryFrom, fmt}; -use uint::construct_uint; // U128 with 128 bits consisting of 2 x 64-bit words construct_uint! { diff --git a/token-lending/program/src/processor.rs b/token-lending/program/src/processor.rs index a93d5669b1d..61a1710fc51 100644 --- a/token-lending/program/src/processor.rs +++ b/token-lending/program/src/processor.rs @@ -1,33 +1,37 @@ //! Program state processor -use crate::{ - error::LendingError, - instruction::LendingInstruction, - math::{Decimal, Rate, TryAdd, TryDiv, TryMul}, - pyth, - state::{ - CalculateBorrowResult, CalculateLiquidationResult, CalculateRepayResult, - InitLendingMarketParams, InitObligationParams, InitReserveParams, LendingMarket, - NewReserveCollateralParams, NewReserveLiquidityParams, Obligation, Reserve, - ReserveCollateral, ReserveConfig, ReserveLiquidity, +use { + crate::{ + error::LendingError, + instruction::LendingInstruction, + math::{Decimal, Rate, TryAdd, TryDiv, TryMul}, + pyth, + state::{ + CalculateBorrowResult, CalculateLiquidationResult, CalculateRepayResult, + InitLendingMarketParams, InitObligationParams, InitReserveParams, LendingMarket, + NewReserveCollateralParams, NewReserveLiquidityParams, Obligation, Reserve, + ReserveCollateral, ReserveConfig, ReserveLiquidity, + }, }, + num_traits::FromPrimitive, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + decode_error::DecodeError, + entrypoint::ProgramResult, + instruction::Instruction, + msg, + program::{invoke, invoke_signed}, + program_error::{PrintProgramError, ProgramError}, + program_pack::{IsInitialized, Pack}, + pubkey::Pubkey, + sysvar::{clock::Clock, rent::Rent, Sysvar}, + }, + spl_token::{ + solana_program::instruction::AccountMeta, + state::{Account, Mint}, + }, + std::convert::TryInto, }; -use num_traits::FromPrimitive; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - decode_error::DecodeError, - entrypoint::ProgramResult, - instruction::Instruction, - msg, - program::{invoke, invoke_signed}, - program_error::{PrintProgramError, ProgramError}, - program_pack::{IsInitialized, Pack}, - pubkey::Pubkey, - sysvar::{clock::Clock, rent::Rent, Sysvar}, -}; -use spl_token::solana_program::instruction::AccountMeta; -use spl_token::state::{Account, Mint}; -use std::convert::TryInto; /// Processes an instruction pub fn process_instruction( diff --git a/token-lending/program/src/state/last_update.rs b/token-lending/program/src/state/last_update.rs index 68f95de7799..11fd10c0ae0 100644 --- a/token-lending/program/src/state/last_update.rs +++ b/token-lending/program/src/state/last_update.rs @@ -1,6 +1,8 @@ -use crate::error::LendingError; -use solana_program::{clock::Slot, program_error::ProgramError}; -use std::cmp::Ordering; +use { + crate::error::LendingError, + solana_program::{clock::Slot, program_error::ProgramError}, + std::cmp::Ordering, +}; /// Number of slots to consider stale after pub const STALE_AFTER_SLOTS_ELAPSED: u64 = 1; diff --git a/token-lending/program/src/state/lending_market.rs b/token-lending/program/src/state/lending_market.rs index 82b47e1d22d..457767d8bd8 100644 --- a/token-lending/program/src/state/lending_market.rs +++ b/token-lending/program/src/state/lending_market.rs @@ -1,10 +1,12 @@ -use super::*; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use solana_program::{ - msg, - program_error::ProgramError, - program_pack::{IsInitialized, Pack, Sealed}, - pubkey::{Pubkey, PUBKEY_BYTES}, +use { + super::*, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + solana_program::{ + msg, + program_error::ProgramError, + program_pack::{IsInitialized, Pack, Sealed}, + pubkey::{Pubkey, PUBKEY_BYTES}, + }, }; /// Lending market state diff --git a/token-lending/program/src/state/mod.rs b/token-lending/program/src/state/mod.rs index 55496a253e7..9f056916bf1 100644 --- a/token-lending/program/src/state/mod.rs +++ b/token-lending/program/src/state/mod.rs @@ -5,17 +5,15 @@ mod lending_market; mod obligation; mod reserve; -pub use last_update::*; -pub use lending_market::*; -pub use obligation::*; -pub use reserve::*; - -use crate::math::{Decimal, WAD}; -use solana_program::{ - clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, SECONDS_PER_DAY}, - msg, - program_error::ProgramError, +use { + crate::math::{Decimal, WAD}, + solana_program::{ + clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, SECONDS_PER_DAY}, + msg, + program_error::ProgramError, + }, }; +pub use {last_update::*, lending_market::*, obligation::*, reserve::*}; /// Collateral tokens are initially valued at a ratio of 5:1 (collateral:liquidity) // @FIXME: restore to 5 diff --git a/token-lending/program/src/state/obligation.rs b/token-lending/program/src/state/obligation.rs index 5182b4f9e37..637fd8e31db 100644 --- a/token-lending/program/src/state/obligation.rs +++ b/token-lending/program/src/state/obligation.rs @@ -1,20 +1,22 @@ -use super::*; -use crate::{ - error::LendingError, - math::{Decimal, Rate, TryAdd, TryDiv, TryMul, TrySub}, -}; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use solana_program::{ - clock::Slot, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - program_pack::{IsInitialized, Pack, Sealed}, - pubkey::{Pubkey, PUBKEY_BYTES}, -}; -use std::{ - cmp::Ordering, - convert::{TryFrom, TryInto}, +use { + super::*, + crate::{ + error::LendingError, + math::{Decimal, Rate, TryAdd, TryDiv, TryMul, TrySub}, + }, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + solana_program::{ + clock::Slot, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, + program_pack::{IsInitialized, Pack, Sealed}, + pubkey::{Pubkey, PUBKEY_BYTES}, + }, + std::{ + cmp::Ordering, + convert::{TryFrom, TryInto}, + }, }; /// Max number of collateral and liquidity reserve accounts combined for an obligation @@ -502,9 +504,7 @@ impl Pack for Obligation { #[cfg(test)] mod test { - use super::*; - use crate::math::TryAdd; - use proptest::prelude::*; + use {super::*, crate::math::TryAdd, proptest::prelude::*}; const MAX_COMPOUNDED_INTEREST: u64 = 100; // 10,000% diff --git a/token-lending/program/src/state/reserve.rs b/token-lending/program/src/state/reserve.rs index 332d5a92121..21e798a3422 100644 --- a/token-lending/program/src/state/reserve.rs +++ b/token-lending/program/src/state/reserve.rs @@ -1,20 +1,22 @@ -use super::*; -use crate::{ - error::LendingError, - math::{Decimal, Rate, TryAdd, TryDiv, TryMul, TrySub}, -}; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use solana_program::{ - clock::Slot, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - program_pack::{IsInitialized, Pack, Sealed}, - pubkey::{Pubkey, PUBKEY_BYTES}, -}; -use std::{ - cmp::Ordering, - convert::{TryFrom, TryInto}, +use { + super::*, + crate::{ + error::LendingError, + math::{Decimal, Rate, TryAdd, TryDiv, TryMul, TrySub}, + }, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + solana_program::{ + clock::Slot, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, + program_pack::{IsInitialized, Pack, Sealed}, + pubkey::{Pubkey, PUBKEY_BYTES}, + }, + std::{ + cmp::Ordering, + convert::{TryFrom, TryInto}, + }, }; /// Percentage of an obligation that can be repaid during each liquidation call @@ -982,10 +984,12 @@ impl Pack for Reserve { #[cfg(test)] mod test { - use super::*; - use crate::math::{PERCENT_SCALER, WAD}; - use proptest::prelude::*; - use std::cmp::Ordering; + use { + super::*, + crate::math::{PERCENT_SCALER, WAD}, + proptest::prelude::*, + std::cmp::Ordering, + }; const MAX_LIQUIDITY: u64 = u64::MAX / 5; diff --git a/token-lending/program/tests/borrow_obligation_liquidity.rs b/token-lending/program/tests/borrow_obligation_liquidity.rs index 410d68926c0..04cf626e884 100644 --- a/token-lending/program/tests/borrow_obligation_liquidity.rs +++ b/token-lending/program/tests/borrow_obligation_liquidity.rs @@ -3,21 +3,23 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, + instruction::{borrow_obligation_liquidity, refresh_obligation}, + math::Decimal, + processor::process_instruction, + state::{FeeCalculation, INITIAL_COLLATERAL_RATIO}, + }, + std::u64, }; -use spl_token_lending::{ - error::LendingError, - instruction::{borrow_obligation_liquidity, refresh_obligation}, - math::Decimal, - processor::process_instruction, - state::{FeeCalculation, INITIAL_COLLATERAL_RATIO}, -}; -use std::u64; #[tokio::test] async fn test_borrow_usdc_fixed_amount() { diff --git a/token-lending/program/tests/deposit_obligation_collateral.rs b/token-lending/program/tests/deposit_obligation_collateral.rs index 0e44cb6bb55..cf2e3bcc828 100644 --- a/token-lending/program/tests/deposit_obligation_collateral.rs +++ b/token-lending/program/tests/deposit_obligation_collateral.rs @@ -3,16 +3,18 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token::instruction::approve; -use spl_token_lending::{ - instruction::deposit_obligation_collateral, processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token::instruction::approve, + spl_token_lending::{ + instruction::deposit_obligation_collateral, processor::process_instruction, + state::INITIAL_COLLATERAL_RATIO, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/deposit_reserve_liquidity.rs b/token-lending/program/tests/deposit_reserve_liquidity.rs index 828a54ba816..9e880687ad6 100644 --- a/token-lending/program/tests/deposit_reserve_liquidity.rs +++ b/token-lending/program/tests/deposit_reserve_liquidity.rs @@ -3,10 +3,10 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::signature::Keypair; -use spl_token_lending::processor::process_instruction; +use { + helpers::*, solana_program_test::*, solana_sdk::signature::Keypair, + spl_token_lending::processor::process_instruction, +}; #[tokio::test] async fn test_success() { diff --git a/token-lending/program/tests/flash_loan.rs b/token-lending/program/tests/flash_loan.rs index 0c59c948363..061c73a1bd5 100644 --- a/token-lending/program/tests/flash_loan.rs +++ b/token-lending/program/tests/flash_loan.rs @@ -3,17 +3,19 @@ mod helpers; -use helpers::*; -use solana_program::instruction::AccountMeta; -use solana_program_test::*; -use solana_sdk::{ - pubkey::Pubkey, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_token::solana_program::instruction::InstructionError; -use spl_token_lending::{ - error::LendingError, instruction::flash_loan, processor::process_instruction, +use { + helpers::*, + solana_program::instruction::AccountMeta, + solana_program_test::*, + solana_sdk::{ + pubkey::Pubkey, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token::solana_program::instruction::InstructionError, + spl_token_lending::{ + error::LendingError, instruction::flash_loan, processor::process_instruction, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/helpers/flash_loan_receiver.rs b/token-lending/program/tests/helpers/flash_loan_receiver.rs index b5aa7ae57e8..6c19e6e36af 100644 --- a/token-lending/program/tests/helpers/flash_loan_receiver.rs +++ b/token-lending/program/tests/helpers/flash_loan_receiver.rs @@ -1,16 +1,16 @@ -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey}; - -use crate::helpers::flash_loan_receiver::FlashLoanReceiverError::InvalidInstruction; -use spl_token::{ - solana_program::{ - account_info::next_account_info, program::invoke_signed, program_error::ProgramError, - program_pack::Pack, +use { + crate::helpers::flash_loan_receiver::FlashLoanReceiverError::InvalidInstruction, + solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey}, + spl_token::{ + solana_program::{ + account_info::next_account_info, program::invoke_signed, program_error::ProgramError, + program_pack::Pack, + }, + state::Account, }, - state::Account, + std::{cmp::min, convert::TryInto}, + thiserror::Error, }; -use std::cmp::min; -use std::convert::TryInto; -use thiserror::Error; pub enum FlashLoanReceiverInstruction { /// Receive a flash loan and perform user-defined operation and finally return the fund back. diff --git a/token-lending/program/tests/helpers/mod.rs b/token-lending/program/tests/helpers/mod.rs index baea93c9221..9c6c873e2ea 100644 --- a/token-lending/program/tests/helpers/mod.rs +++ b/token-lending/program/tests/helpers/mod.rs @@ -2,34 +2,36 @@ pub mod flash_loan_receiver; -use assert_matches::*; -use solana_program::{program_option::COption, program_pack::Pack, pubkey::Pubkey}; -use solana_program_test::*; -use solana_sdk::{ - account::Account, - signature::{read_keypair_file, Keypair, Signer}, - system_instruction::create_account, - transaction::{Transaction, TransactionError}, -}; -use spl_token::{ - instruction::approve, - state::{Account as Token, AccountState, Mint}, -}; -use spl_token_lending::{ - instruction::{ - borrow_obligation_liquidity, deposit_reserve_liquidity, init_lending_market, - init_obligation, init_reserve, liquidate_obligation, refresh_reserve, +use { + assert_matches::*, + solana_program::{program_option::COption, program_pack::Pack, pubkey::Pubkey}, + solana_program_test::*, + solana_sdk::{ + account::Account, + signature::{read_keypair_file, Keypair, Signer}, + system_instruction::create_account, + transaction::{Transaction, TransactionError}, + }, + spl_token::{ + instruction::approve, + state::{Account as Token, AccountState, Mint}, }, - math::{Decimal, Rate, TryAdd, TryMul}, - pyth, - state::{ - InitLendingMarketParams, InitObligationParams, InitReserveParams, LendingMarket, - NewReserveCollateralParams, NewReserveLiquidityParams, Obligation, ObligationCollateral, - ObligationLiquidity, Reserve, ReserveCollateral, ReserveConfig, ReserveFees, - ReserveLiquidity, INITIAL_COLLATERAL_RATIO, PROGRAM_VERSION, + spl_token_lending::{ + instruction::{ + borrow_obligation_liquidity, deposit_reserve_liquidity, init_lending_market, + init_obligation, init_reserve, liquidate_obligation, refresh_reserve, + }, + math::{Decimal, Rate, TryAdd, TryMul}, + pyth, + state::{ + InitLendingMarketParams, InitObligationParams, InitReserveParams, LendingMarket, + NewReserveCollateralParams, NewReserveLiquidityParams, Obligation, + ObligationCollateral, ObligationLiquidity, Reserve, ReserveCollateral, ReserveConfig, + ReserveFees, ReserveLiquidity, INITIAL_COLLATERAL_RATIO, PROGRAM_VERSION, + }, }, + std::{convert::TryInto, str::FromStr}, }; -use std::{convert::TryInto, str::FromStr}; pub const QUOTE_CURRENCY: [u8; 32] = *b"USD\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; diff --git a/token-lending/program/tests/init_lending_market.rs b/token-lending/program/tests/init_lending_market.rs index 659ce8ff7c6..ed0aebdd9bf 100644 --- a/token-lending/program/tests/init_lending_market.rs +++ b/token-lending/program/tests/init_lending_market.rs @@ -3,15 +3,17 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::Signer, - transaction::{Transaction, TransactionError}, -}; -use spl_token_lending::{ - error::LendingError, instruction::init_lending_market, processor::process_instruction, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::Signer, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, instruction::init_lending_market, processor::process_instruction, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/init_obligation.rs b/token-lending/program/tests/init_obligation.rs index 365395b8004..60d34a2bb0b 100644 --- a/token-lending/program/tests/init_obligation.rs +++ b/token-lending/program/tests/init_obligation.rs @@ -3,15 +3,17 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_token_lending::{ - error::LendingError, instruction::init_obligation, processor::process_instruction, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, instruction::init_obligation, processor::process_instruction, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/init_reserve.rs b/token-lending/program/tests/init_reserve.rs index ff81ba77b2b..719c44dae46 100644 --- a/token-lending/program/tests/init_reserve.rs +++ b/token-lending/program/tests/init_reserve.rs @@ -3,18 +3,20 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_token_lending::{ - error::LendingError, - instruction::init_reserve, - processor::process_instruction, - state::{ReserveFees, INITIAL_COLLATERAL_RATIO}, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, + instruction::init_reserve, + processor::process_instruction, + state::{ReserveFees, INITIAL_COLLATERAL_RATIO}, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/liquidate_obligation.rs b/token-lending/program/tests/liquidate_obligation.rs index 82c79f86321..df7687fb772 100644 --- a/token-lending/program/tests/liquidate_obligation.rs +++ b/token-lending/program/tests/liquidate_obligation.rs @@ -3,17 +3,19 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token::instruction::approve; -use spl_token_lending::{ - instruction::{liquidate_obligation, refresh_obligation}, - processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token::instruction::approve, + spl_token_lending::{ + instruction::{liquidate_obligation, refresh_obligation}, + processor::process_instruction, + state::INITIAL_COLLATERAL_RATIO, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/modify_reserve_config.rs b/token-lending/program/tests/modify_reserve_config.rs index 4386baf1dac..2f1b0bf3fc1 100644 --- a/token-lending/program/tests/modify_reserve_config.rs +++ b/token-lending/program/tests/modify_reserve_config.rs @@ -3,21 +3,23 @@ mod helpers; -use helpers::*; -use solana_program::pubkey::Pubkey; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::{read_keypair_file, Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_token_lending::{ - error::LendingError, - instruction::modify_reserve_config, - processor::process_instruction, - state::{ - InitLendingMarketParams, LendingMarket, ReserveConfig, ReserveFees, - INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program::pubkey::Pubkey, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::{read_keypair_file, Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, + instruction::modify_reserve_config, + processor::process_instruction, + state::{ + InitLendingMarketParams, LendingMarket, ReserveConfig, ReserveFees, + INITIAL_COLLATERAL_RATIO, + }, }, }; diff --git a/token-lending/program/tests/obligation_end_to_end.rs b/token-lending/program/tests/obligation_end_to_end.rs index badb9450378..57b66d125f3 100644 --- a/token-lending/program/tests/obligation_end_to_end.rs +++ b/token-lending/program/tests/obligation_end_to_end.rs @@ -3,24 +3,26 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - account::Account, - signature::{Keypair, Signer}, - system_instruction::create_account, - transaction::Transaction, -}; -use spl_token::{instruction::approve, solana_program::program_pack::Pack}; -use spl_token_lending::{ - instruction::{ - borrow_obligation_liquidity, deposit_obligation_collateral, init_obligation, - refresh_obligation, refresh_reserve, repay_obligation_liquidity, - withdraw_obligation_collateral, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + account::Account, + signature::{Keypair, Signer}, + system_instruction::create_account, + transaction::Transaction, + }, + spl_token::{instruction::approve, solana_program::program_pack::Pack}, + spl_token_lending::{ + instruction::{ + borrow_obligation_liquidity, deposit_obligation_collateral, init_obligation, + refresh_obligation, refresh_reserve, repay_obligation_liquidity, + withdraw_obligation_collateral, + }, + math::Decimal, + processor::process_instruction, + state::{Obligation, INITIAL_COLLATERAL_RATIO}, }, - math::Decimal, - processor::process_instruction, - state::{Obligation, INITIAL_COLLATERAL_RATIO}, }; #[tokio::test] diff --git a/token-lending/program/tests/redeem_reserve_collateral.rs b/token-lending/program/tests/redeem_reserve_collateral.rs index a72cacd4e84..0340065bf68 100644 --- a/token-lending/program/tests/redeem_reserve_collateral.rs +++ b/token-lending/program/tests/redeem_reserve_collateral.rs @@ -3,16 +3,18 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token::instruction::approve; -use spl_token_lending::{ - instruction::redeem_reserve_collateral, processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token::instruction::approve, + spl_token_lending::{ + instruction::redeem_reserve_collateral, processor::process_instruction, + state::INITIAL_COLLATERAL_RATIO, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/refresh_obligation.rs b/token-lending/program/tests/refresh_obligation.rs index cb2b20cf7e7..e07e948ec75 100644 --- a/token-lending/program/tests/refresh_obligation.rs +++ b/token-lending/program/tests/refresh_obligation.rs @@ -3,19 +3,19 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token_lending::math::{Rate, TryAdd, TryMul}; -use spl_token_lending::state::SLOTS_PER_YEAR; -use spl_token_lending::{ - instruction::{refresh_obligation, refresh_reserve}, - math::{Decimal, TryDiv}, - processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token_lending::{ + instruction::{refresh_obligation, refresh_reserve}, + math::{Decimal, Rate, TryAdd, TryDiv, TryMul}, + processor::process_instruction, + state::{INITIAL_COLLATERAL_RATIO, SLOTS_PER_YEAR}, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/refresh_reserve.rs b/token-lending/program/tests/refresh_reserve.rs index 0b73943188c..66ace0fef70 100644 --- a/token-lending/program/tests/refresh_reserve.rs +++ b/token-lending/program/tests/refresh_reserve.rs @@ -3,17 +3,19 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token_lending::{ - instruction::refresh_reserve, - math::{Decimal, Rate, TryAdd, TryDiv, TryMul}, - processor::process_instruction, - state::SLOTS_PER_YEAR, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token_lending::{ + instruction::refresh_reserve, + math::{Decimal, Rate, TryAdd, TryDiv, TryMul}, + processor::process_instruction, + state::SLOTS_PER_YEAR, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/repay_obligation_liquidity.rs b/token-lending/program/tests/repay_obligation_liquidity.rs index 1fe9e6275b2..0b1dc5eeb39 100644 --- a/token-lending/program/tests/repay_obligation_liquidity.rs +++ b/token-lending/program/tests/repay_obligation_liquidity.rs @@ -3,17 +3,19 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - signature::{Keypair, Signer}, - transaction::Transaction, -}; -use spl_token::instruction::approve; -use spl_token_lending::instruction::refresh_obligation; -use spl_token_lending::{ - instruction::repay_obligation_liquidity, processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + signature::{Keypair, Signer}, + transaction::Transaction, + }, + spl_token::instruction::approve, + spl_token_lending::{ + instruction::{refresh_obligation, repay_obligation_liquidity}, + processor::process_instruction, + state::INITIAL_COLLATERAL_RATIO, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/set_lending_market_owner.rs b/token-lending/program/tests/set_lending_market_owner.rs index 40315b85d90..9f120aa9b65 100644 --- a/token-lending/program/tests/set_lending_market_owner.rs +++ b/token-lending/program/tests/set_lending_market_owner.rs @@ -3,19 +3,21 @@ mod helpers; -use helpers::*; -use solana_program::instruction::{AccountMeta, Instruction}; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - pubkey::Pubkey, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, -}; -use spl_token_lending::{ - error::LendingError, - instruction::{set_lending_market_owner, LendingInstruction}, - processor::process_instruction, +use { + helpers::*, + solana_program::instruction::{AccountMeta, Instruction}, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + pubkey::Pubkey, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, + instruction::{set_lending_market_owner, LendingInstruction}, + processor::process_instruction, + }, }; #[tokio::test] diff --git a/token-lending/program/tests/withdraw_obligation_collateral.rs b/token-lending/program/tests/withdraw_obligation_collateral.rs index 1e68b5d80e1..f7ebba720de 100644 --- a/token-lending/program/tests/withdraw_obligation_collateral.rs +++ b/token-lending/program/tests/withdraw_obligation_collateral.rs @@ -3,20 +3,22 @@ mod helpers; -use helpers::*; -use solana_program_test::*; -use solana_sdk::{ - instruction::InstructionError, - signature::{Keypair, Signer}, - transaction::{Transaction, TransactionError}, +use { + helpers::*, + solana_program_test::*, + solana_sdk::{ + instruction::InstructionError, + signature::{Keypair, Signer}, + transaction::{Transaction, TransactionError}, + }, + spl_token_lending::{ + error::LendingError, + instruction::{refresh_obligation, withdraw_obligation_collateral}, + processor::process_instruction, + state::INITIAL_COLLATERAL_RATIO, + }, + std::u64, }; -use spl_token_lending::{ - error::LendingError, - instruction::{refresh_obligation, withdraw_obligation_collateral}, - processor::process_instruction, - state::INITIAL_COLLATERAL_RATIO, -}; -use std::u64; #[tokio::test] async fn test_withdraw_fixed_amount() { diff --git a/token-metadata/interface/src/instruction.rs b/token-metadata/interface/src/instruction.rs index 30865d391a2..89ad991de73 100644 --- a/token-metadata/interface/src/instruction.rs +++ b/token-metadata/interface/src/instruction.rs @@ -1,5 +1,7 @@ //! Instruction types +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::state::Field, borsh::{BorshDeserialize, BorshSerialize}, @@ -12,9 +14,6 @@ use { spl_pod::optional_keys::OptionalNonZeroPubkey, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Initialization instruction data #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] @@ -320,10 +319,9 @@ pub fn emit( #[cfg(test)] mod test { - use {super::*, crate::NAMESPACE, solana_program::hash}; - #[cfg(feature = "serde-traits")] use std::str::FromStr; + use {super::*, crate::NAMESPACE, solana_program::hash}; fn check_pack_unpack( instruction: TokenMetadataInstruction, diff --git a/token-metadata/interface/src/lib.rs b/token-metadata/interface/src/lib.rs index 5f1ec043e13..5302765e492 100644 --- a/token-metadata/interface/src/lib.rs +++ b/token-metadata/interface/src/lib.rs @@ -9,9 +9,8 @@ pub mod instruction; pub mod state; // Export current sdk types for downstream users building with a different sdk version -pub use solana_program; // Export borsh for downstream users -pub use borsh; +pub use {borsh, solana_program}; /// Namespace for all programs implementing token-metadata pub const NAMESPACE: &str = "spl_token_metadata_interface"; diff --git a/token-metadata/interface/src/state.rs b/token-metadata/interface/src/state.rs index 08e54291bbb..6f5fe54d3fc 100644 --- a/token-metadata/interface/src/state.rs +++ b/token-metadata/interface/src/state.rs @@ -1,5 +1,7 @@ //! Token-metadata interface state types +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, solana_program::{ @@ -15,9 +17,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Data struct for all token-metadata, stored in a TLV entry /// /// The type and length parts must be handled by the TLV library, and not stored diff --git a/token-swap/program/fuzz/src/native_processor.rs b/token-swap/program/fuzz/src/native_processor.rs index 6115197c4bd..3e451d65e68 100644 --- a/token-swap/program/fuzz/src/native_processor.rs +++ b/token-swap/program/fuzz/src/native_processor.rs @@ -1,8 +1,9 @@ -use crate::native_account_data::NativeAccountData; - -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction, - program_error::ProgramError, program_stubs, pubkey::Pubkey, +use { + crate::native_account_data::NativeAccountData, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction, + program_error::ProgramError, program_stubs, pubkey::Pubkey, + }, }; struct TestSyscallStubs {} diff --git a/token-swap/program/fuzz/src/native_token.rs b/token-swap/program/fuzz/src/native_token.rs index b1235c2f1e4..9b7981c43ab 100644 --- a/token-swap/program/fuzz/src/native_token.rs +++ b/token-swap/program/fuzz/src/native_token.rs @@ -1,8 +1,8 @@ -use crate::native_account_data::NativeAccountData; - -use spl_token::state::{Account as TokenAccount, AccountState as TokenAccountState, Mint}; - -use solana_program::{program_option::COption, program_pack::Pack, pubkey::Pubkey}; +use { + crate::native_account_data::NativeAccountData, + solana_program::{program_option::COption, program_pack::Pack, pubkey::Pubkey}, + spl_token::state::{Account as TokenAccount, AccountState as TokenAccountState, Mint}, +}; pub fn create_mint(owner: &Pubkey) -> NativeAccountData { let mut account_data = NativeAccountData::new(Mint::LEN, spl_token::id()); diff --git a/token-swap/program/fuzz/src/native_token_swap.rs b/token-swap/program/fuzz/src/native_token_swap.rs index ff62f293590..0ca6731edbc 100644 --- a/token-swap/program/fuzz/src/native_token_swap.rs +++ b/token-swap/program/fuzz/src/native_token_swap.rs @@ -1,22 +1,22 @@ //! Helpers for working with swaps in a fuzzing environment -use crate::native_account_data::NativeAccountData; -use crate::native_processor::do_process_instruction; -use crate::native_token; - -use spl_token_swap::{ - curve::{base::SwapCurve, calculator::TradeDirection, fees::Fees}, - instruction::{ - self, DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Swap, - WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut, +use { + crate::{ + native_account_data::NativeAccountData, native_processor::do_process_instruction, + native_token, + }, + solana_program::{bpf_loader, entrypoint::ProgramResult, pubkey::Pubkey, system_program}, + spl_token::instruction::approve, + spl_token_swap::{ + curve::{base::SwapCurve, calculator::TradeDirection, fees::Fees}, + instruction::{ + self, DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Swap, + WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut, + }, + state::SwapVersion, }, - state::SwapVersion, }; -use spl_token::instruction::approve; - -use solana_program::{bpf_loader, entrypoint::ProgramResult, pubkey::Pubkey, system_program}; - pub struct NativeTokenSwap { pub user_account: NativeAccountData, pub bump_seed: u8, diff --git a/token-swap/program/src/constraints.rs b/token-swap/program/src/constraints.rs index 4498af07304..99e3d1b4564 100644 --- a/token-swap/program/src/constraints.rs +++ b/token-swap/program/src/constraints.rs @@ -1,16 +1,17 @@ //! Various constraints as required for production environments -use crate::{ - curve::{ - base::{CurveType, SwapCurve}, - fees::Fees, - }, - error::SwapError, -}; -use solana_program::program_error::ProgramError; - #[cfg(feature = "production")] use std::env; +use { + crate::{ + curve::{ + base::{CurveType, SwapCurve}, + fees::Fees, + }, + error::SwapError, + }, + solana_program::program_error::ProgramError, +}; /// Encodes fee constraints, used in multihost environments where the program /// may be used by multiple frontends, to ensure that proper fees are being @@ -98,9 +99,11 @@ pub const SWAP_CONSTRAINTS: Option = { #[cfg(test)] mod tests { - use super::*; - use crate::curve::{base::CurveType, constant_product::ConstantProductCurve}; - use std::sync::Arc; + use { + super::*, + crate::curve::{base::CurveType, constant_product::ConstantProductCurve}, + std::sync::Arc, + }; #[test] fn validate_fees() { diff --git a/token-swap/program/src/curve/base.rs b/token-swap/program/src/curve/base.rs index b90585b12c7..823c561736a 100644 --- a/token-swap/program/src/curve/base.rs +++ b/token-swap/program/src/curve/base.rs @@ -1,24 +1,26 @@ //! Base curve implementation -use solana_program::{ - program_error::ProgramError, - program_pack::{Pack, Sealed}, -}; - -use crate::curve::{ - calculator::{CurveCalculator, RoundDirection, SwapWithoutFeesResult, TradeDirection}, - constant_price::ConstantPriceCurve, - constant_product::ConstantProductCurve, - fees::Fees, - offset::OffsetCurve, -}; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use std::convert::{TryFrom, TryInto}; -use std::fmt::Debug; -use std::sync::Arc; - #[cfg(feature = "fuzz")] use arbitrary::Arbitrary; +use { + crate::curve::{ + calculator::{CurveCalculator, RoundDirection, SwapWithoutFeesResult, TradeDirection}, + constant_price::ConstantPriceCurve, + constant_product::ConstantProductCurve, + fees::Fees, + offset::OffsetCurve, + }, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + solana_program::{ + program_error::ProgramError, + program_pack::{Pack, Sealed}, + }, + std::{ + convert::{TryFrom, TryInto}, + fmt::Debug, + sync::Arc, + }, +}; /// Curve types supported by the token-swap program. #[cfg_attr(feature = "fuzz", derive(Arbitrary))] @@ -262,9 +264,7 @@ impl TryFrom for CurveType { #[cfg(test)] mod test { - use super::*; - use crate::curve::calculator::test::total_and_intermediate; - use proptest::prelude::*; + use {super::*, crate::curve::calculator::test::total_and_intermediate, proptest::prelude::*}; #[test] fn pack_swap_curve() { diff --git a/token-swap/program/src/curve/calculator.rs b/token-swap/program/src/curve/calculator.rs index 2ff06960b85..baa20f0ec8a 100644 --- a/token-swap/program/src/curve/calculator.rs +++ b/token-swap/program/src/curve/calculator.rs @@ -1,9 +1,8 @@ //! Swap calculations -use {crate::error::SwapError, spl_math::precise_number::PreciseNumber, std::fmt::Debug}; - #[cfg(feature = "fuzz")] use arbitrary::Arbitrary; +use {crate::error::SwapError, spl_math::precise_number::PreciseNumber, std::fmt::Debug}; /// Initial amount of pool tokens for swap contract, hard-coded to something /// "sensible" given a maximum of u128. @@ -195,9 +194,7 @@ pub trait CurveCalculator: Debug + DynPack { /// Test helpers for curves #[cfg(test)] pub mod test { - use super::*; - use proptest::prelude::*; - use spl_math::uint::U256; + use {super::*, proptest::prelude::*, spl_math::uint::U256}; /// The epsilon for most curves when performing the conversion test, /// comparing a one-sided deposit to a swap + deposit. diff --git a/token-swap/program/src/curve/constant_price.rs b/token-swap/program/src/curve/constant_price.rs index 7b66df3058a..4f3f026320d 100644 --- a/token-swap/program/src/curve/constant_price.rs +++ b/token-swap/program/src/curve/constant_price.rs @@ -262,16 +262,18 @@ impl DynPack for ConstantPriceCurve { #[cfg(test)] mod tests { - use super::*; - use crate::curve::calculator::{ - test::{ - check_curve_value_from_swap, check_deposit_token_conversion, - check_withdraw_token_conversion, total_and_intermediate, - CONVERSION_BASIS_POINTS_GUARANTEE, + use { + super::*, + crate::curve::calculator::{ + test::{ + check_curve_value_from_swap, check_deposit_token_conversion, + check_withdraw_token_conversion, total_and_intermediate, + CONVERSION_BASIS_POINTS_GUARANTEE, + }, + INITIAL_SWAP_POOL_AMOUNT, }, - INITIAL_SWAP_POOL_AMOUNT, + proptest::prelude::*, }; - use proptest::prelude::*; #[test] fn swap_calculation_no_price() { diff --git a/token-swap/program/src/curve/constant_product.rs b/token-swap/program/src/curve/constant_product.rs index 7195119f93a..7de5bb3350f 100644 --- a/token-swap/program/src/curve/constant_product.rs +++ b/token-swap/program/src/curve/constant_product.rs @@ -278,17 +278,19 @@ impl DynPack for ConstantProductCurve { #[cfg(test)] mod tests { - use super::*; - use crate::curve::calculator::{ - test::{ - check_curve_value_from_swap, check_deposit_token_conversion, - check_pool_value_from_deposit, check_pool_value_from_withdraw, - check_withdraw_token_conversion, total_and_intermediate, - CONVERSION_BASIS_POINTS_GUARANTEE, + use { + super::*, + crate::curve::calculator::{ + test::{ + check_curve_value_from_swap, check_deposit_token_conversion, + check_pool_value_from_deposit, check_pool_value_from_withdraw, + check_withdraw_token_conversion, total_and_intermediate, + CONVERSION_BASIS_POINTS_GUARANTEE, + }, + RoundDirection, INITIAL_SWAP_POOL_AMOUNT, }, - RoundDirection, INITIAL_SWAP_POOL_AMOUNT, + proptest::prelude::*, }; - use proptest::prelude::*; #[test] fn initial_pool_amount() { diff --git a/token-swap/program/src/curve/fees.rs b/token-swap/program/src/curve/fees.rs index 4fe8fd2fb3d..9a5abc748cf 100644 --- a/token-swap/program/src/curve/fees.rs +++ b/token-swap/program/src/curve/fees.rs @@ -1,12 +1,14 @@ //! All fee information, to be used for validation currently -use crate::error::SwapError; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use solana_program::{ - program_error::ProgramError, - program_pack::{IsInitialized, Pack, Sealed}, +use { + crate::error::SwapError, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + solana_program::{ + program_error::ProgramError, + program_pack::{IsInitialized, Pack, Sealed}, + }, + std::convert::TryFrom, }; -use std::convert::TryFrom; /// Encapsulates all fee information and calculations for swap operations #[derive(Clone, Debug, Default, PartialEq)] diff --git a/token-swap/program/src/curve/offset.rs b/token-swap/program/src/curve/offset.rs index cae8bdde0a6..7c9e37e4dc1 100644 --- a/token-swap/program/src/curve/offset.rs +++ b/token-swap/program/src/curve/offset.rs @@ -186,17 +186,19 @@ impl DynPack for OffsetCurve { #[cfg(test)] mod tests { - use super::*; - use crate::curve::calculator::{ - test::{ - check_curve_value_from_swap, check_deposit_token_conversion, - check_pool_value_from_deposit, check_pool_value_from_withdraw, - check_withdraw_token_conversion, total_and_intermediate, - CONVERSION_BASIS_POINTS_GUARANTEE, + use { + super::*, + crate::curve::calculator::{ + test::{ + check_curve_value_from_swap, check_deposit_token_conversion, + check_pool_value_from_deposit, check_pool_value_from_withdraw, + check_withdraw_token_conversion, total_and_intermediate, + CONVERSION_BASIS_POINTS_GUARANTEE, + }, + INITIAL_SWAP_POOL_AMOUNT, }, - INITIAL_SWAP_POOL_AMOUNT, + proptest::prelude::*, }; - use proptest::prelude::*; #[test] fn pack_curve() { diff --git a/token-swap/program/src/entrypoint.rs b/token-swap/program/src/entrypoint.rs index 206f51456d7..a8ae2f338cf 100644 --- a/token-swap/program/src/entrypoint.rs +++ b/token-swap/program/src/entrypoint.rs @@ -1,9 +1,11 @@ //! Program entrypoint definitions -use crate::{error::SwapError, processor::Processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::SwapError, processor::Processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/token-swap/program/src/error.rs b/token-swap/program/src/error.rs index 78da9e06910..f950a6b50ef 100644 --- a/token-swap/program/src/error.rs +++ b/token-swap/program/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the TokenSwap program. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/token-swap/program/src/instruction.rs b/token-swap/program/src/instruction.rs index 783494b926a..3586b0d8ae2 100644 --- a/token-swap/program/src/instruction.rs +++ b/token-swap/program/src/instruction.rs @@ -2,19 +2,21 @@ #![allow(clippy::too_many_arguments)] -use crate::curve::{base::SwapCurve, fees::Fees}; -use crate::error::SwapError; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - program_pack::Pack, - pubkey::Pubkey, -}; -use std::convert::TryInto; -use std::mem::size_of; - #[cfg(feature = "fuzz")] use arbitrary::Arbitrary; +use { + crate::{ + curve::{base::SwapCurve, fees::Fees}, + error::SwapError, + }, + solana_program::{ + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + program_pack::Pack, + pubkey::Pubkey, + }, + std::{convert::TryInto, mem::size_of}, +}; /// Initialize instruction data #[repr(C)] @@ -613,9 +615,11 @@ pub fn unpack(input: &[u8]) -> Result<&T, ProgramError> { #[cfg(test)] mod tests { - use super::*; - use crate::curve::{base::CurveType, offset::OffsetCurve}; - use std::sync::Arc; + use { + super::*, + crate::curve::{base::CurveType, offset::OffsetCurve}, + std::sync::Arc, + }; #[test] fn pack_intialize() { diff --git a/token-swap/program/src/processor.rs b/token-swap/program/src/processor.rs index 567acfc1c12..de212c31d27 100644 --- a/token-swap/program/src/processor.rs +++ b/token-swap/program/src/processor.rs @@ -1,43 +1,45 @@ //! Program state processor -use crate::constraints::{SwapConstraints, SWAP_CONSTRAINTS}; -use crate::{ - curve::{ - base::SwapCurve, - calculator::{RoundDirection, TradeDirection}, - fees::Fees, +use { + crate::{ + constraints::{SwapConstraints, SWAP_CONSTRAINTS}, + curve::{ + base::SwapCurve, + calculator::{RoundDirection, TradeDirection}, + fees::Fees, + }, + error::SwapError, + instruction::{ + DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Initialize, Swap, + SwapInstruction, WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut, + }, + state::{SwapState, SwapV1, SwapVersion}, }, - error::SwapError, - instruction::{ - DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Initialize, Swap, - SwapInstruction, WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut, + num_traits::FromPrimitive, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + clock::Clock, + decode_error::DecodeError, + entrypoint::ProgramResult, + instruction::Instruction, + msg, + program::invoke_signed, + program_error::{PrintProgramError, ProgramError}, + program_option::COption, + pubkey::Pubkey, + sysvar::Sysvar, }, - state::{SwapState, SwapV1, SwapVersion}, -}; -use num_traits::FromPrimitive; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - clock::Clock, - decode_error::DecodeError, - entrypoint::ProgramResult, - instruction::Instruction, - msg, - program::invoke_signed, - program_error::{PrintProgramError, ProgramError}, - program_option::COption, - pubkey::Pubkey, - sysvar::Sysvar, -}; -use spl_token_2022::{ - check_spl_token_program_account, - error::TokenError, - extension::{ - mint_close_authority::MintCloseAuthority, transfer_fee::TransferFeeConfig, - BaseStateWithExtensions, StateWithExtensions, + spl_token_2022::{ + check_spl_token_program_account, + error::TokenError, + extension::{ + mint_close_authority::MintCloseAuthority, transfer_fee::TransferFeeConfig, + BaseStateWithExtensions, StateWithExtensions, + }, + state::{Account, Mint}, }, - state::{Account, Mint}, + std::{convert::TryInto, error::Error}, }; -use std::{convert::TryInto, error::Error}; /// Program state handler. pub struct Processor {} @@ -1271,39 +1273,43 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::{ - curve::calculator::{CurveCalculator, INITIAL_SWAP_POOL_AMOUNT}, - curve::{ - base::CurveType, constant_price::ConstantPriceCurve, - constant_product::ConstantProductCurve, offset::OffsetCurve, + use { + super::*, + crate::{ + curve::{ + base::CurveType, + calculator::{CurveCalculator, INITIAL_SWAP_POOL_AMOUNT}, + constant_price::ConstantPriceCurve, + constant_product::ConstantProductCurve, + offset::OffsetCurve, + }, + instruction::{ + deposit_all_token_types, deposit_single_token_type_exact_amount_in, initialize, + swap, withdraw_all_token_types, withdraw_single_token_type_exact_amount_out, + }, }, - instruction::{ - deposit_all_token_types, deposit_single_token_type_exact_amount_in, initialize, swap, - withdraw_all_token_types, withdraw_single_token_type_exact_amount_out, + solana_program::{ + clock::Clock, entrypoint::SUCCESS, instruction::Instruction, program_pack::Pack, + program_stubs, rent::Rent, }, - }; - use solana_program::{ - clock::Clock, entrypoint::SUCCESS, instruction::Instruction, program_pack::Pack, - program_stubs, rent::Rent, - }; - use solana_sdk::account::{ - create_account_for_test, create_is_signer_account_infos, Account as SolanaAccount, - }; - use spl_token_2022::{ - error::TokenError, - extension::{ - transfer_fee::{instruction::initialize_transfer_fee_config, TransferFee}, - ExtensionType, + solana_sdk::account::{ + create_account_for_test, create_is_signer_account_infos, Account as SolanaAccount, }, - instruction::{ - approve, close_account, freeze_account, initialize_account, initialize_immutable_owner, - initialize_mint, initialize_mint_close_authority, mint_to, revoke, set_authority, - AuthorityType, + spl_token_2022::{ + error::TokenError, + extension::{ + transfer_fee::{instruction::initialize_transfer_fee_config, TransferFee}, + ExtensionType, + }, + instruction::{ + approve, close_account, freeze_account, initialize_account, + initialize_immutable_owner, initialize_mint, initialize_mint_close_authority, + mint_to, revoke, set_authority, AuthorityType, + }, }, + std::sync::Arc, + test_case::test_case, }; - use std::sync::Arc; - use test_case::test_case; // Test program id for the swap program. const SWAP_PROGRAM_ID: Pubkey = Pubkey::new_from_array([2u8; 32]); diff --git a/token-swap/program/src/state.rs b/token-swap/program/src/state.rs index e47553b6940..d0205d8efdc 100644 --- a/token-swap/program/src/state.rs +++ b/token-swap/program/src/state.rs @@ -1,23 +1,25 @@ //! State transition types -use crate::{ - curve::{base::SwapCurve, fees::Fees}, - error::SwapError, +use { + crate::{ + curve::{base::SwapCurve, fees::Fees}, + error::SwapError, + }, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + enum_dispatch::enum_dispatch, + solana_program::{ + account_info::AccountInfo, + msg, + program_error::ProgramError, + program_pack::{IsInitialized, Pack, Sealed}, + pubkey::Pubkey, + }, + spl_token_2022::{ + extension::StateWithExtensions, + state::{Account, AccountState}, + }, + std::sync::Arc, }; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use enum_dispatch::enum_dispatch; -use solana_program::{ - account_info::AccountInfo, - msg, - program_error::ProgramError, - program_pack::{IsInitialized, Pack, Sealed}, - pubkey::Pubkey, -}; -use spl_token_2022::{ - extension::StateWithExtensions, - state::{Account, AccountState}, -}; -use std::sync::Arc; /// Trait representing access to program state across all versions #[enum_dispatch] @@ -281,10 +283,7 @@ impl Pack for SwapV1 { #[cfg(test)] mod tests { - use super::*; - use crate::curve::offset::OffsetCurve; - - use std::convert::TryInto; + use {super::*, crate::curve::offset::OffsetCurve, std::convert::TryInto}; const TEST_FEES: Fees = Fees { trade_fee_numerator: 1, diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index e66cbf7719a..3059994adbe 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -1,28 +1,30 @@ -use crate::{signers_of, Error, MULTISIG_SIGNER_ARG}; -use clap::ArgMatches; -use solana_clap_utils::{ - input_parsers::{pubkey_of_signer, value_of}, - input_validators::normalize_to_url_if_moniker, - keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig}, - nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG}, - offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGN_ONLY_ARG}, +use { + crate::{signers_of, Error, MULTISIG_SIGNER_ARG}, + clap::ArgMatches, + solana_clap_utils::{ + input_parsers::{pubkey_of_signer, value_of}, + input_validators::normalize_to_url_if_moniker, + keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig}, + nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG}, + offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGN_ONLY_ARG}, + }, + solana_cli_output::OutputFormat, + solana_client::nonblocking::rpc_client::RpcClient, + solana_remote_wallet::remote_wallet::RemoteWalletManager, + solana_sdk::{ + account::Account as RawAccount, commitment_config::CommitmentConfig, hash::Hash, + pubkey::Pubkey, signature::Signer, + }, + spl_associated_token_account::*, + spl_token_2022::{ + extension::StateWithExtensionsOwned, + state::{Account, Mint}, + }, + spl_token_client::client::{ + ProgramClient, ProgramOfflineClient, ProgramRpcClient, ProgramRpcClientSendTransaction, + }, + std::{process::exit, rc::Rc, sync::Arc}, }; -use solana_cli_output::OutputFormat; -use solana_client::nonblocking::rpc_client::RpcClient; -use solana_remote_wallet::remote_wallet::RemoteWalletManager; -use solana_sdk::{ - account::Account as RawAccount, commitment_config::CommitmentConfig, hash::Hash, - pubkey::Pubkey, signature::Signer, -}; -use spl_associated_token_account::*; -use spl_token_2022::{ - extension::StateWithExtensionsOwned, - state::{Account, Mint}, -}; -use spl_token_client::client::{ - ProgramClient, ProgramOfflineClient, ProgramRpcClient, ProgramRpcClientSendTransaction, -}; -use std::{process::exit, rc::Rc, sync::Arc}; pub(crate) struct MintInfo { pub program_id: Pubkey, diff --git a/token/cli/src/main.rs b/token/cli/src/main.rs index 07f9978c84e..f73872fbe33 100644 --- a/token/cli/src/main.rs +++ b/token/cli/src/main.rs @@ -1,83 +1,90 @@ #![allow(clippy::arithmetic_side_effects)] -use clap::{ - crate_description, crate_name, crate_version, value_t, value_t_or_exit, App, AppSettings, Arg, - ArgGroup, ArgMatches, SubCommand, -}; -use futures::try_join; -use serde::Serialize; -use solana_account_decoder::{ - parse_token::{get_token_account_mint, parse_token, TokenAccountType, UiAccountState}, - UiAccountData, -}; -use solana_clap_utils::{ - fee_payer::fee_payer_arg, - input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, value_of}, - input_validators::{ - is_amount, is_amount_or_all, is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey, - is_valid_signer, +use { + clap::{ + crate_description, crate_name, crate_version, value_t, value_t_or_exit, App, AppSettings, + Arg, ArgGroup, ArgMatches, SubCommand, }, - keypair::signer_from_path, - memo::memo_arg, - nonce::*, - offline::{self, *}, - ArgConstant, -}; -use solana_cli_output::{ - return_signers_data, CliSignOnlyData, CliSignature, OutputFormat, QuietDisplay, - ReturnSignersConfig, VerboseDisplay, -}; -use solana_client::rpc_request::TokenAccountsFilter; -use solana_remote_wallet::remote_wallet::RemoteWalletManager; -use solana_sdk::{ - instruction::AccountMeta, - native_token::*, - program_option::COption, - pubkey::Pubkey, - signature::{Keypair, Signer}, - system_program, -}; -use spl_associated_token_account::get_associated_token_address_with_program_id; -use spl_token_2022::{ - extension::{ - confidential_transfer::{ - account_info::{ - ApplyPendingBalanceAccountInfo, TransferAccountInfo, WithdrawAccountInfo, - }, - instruction::TransferSplitContextStateAccounts, - ConfidentialTransferAccount, ConfidentialTransferMint, + futures::try_join, + serde::Serialize, + solana_account_decoder::{ + parse_token::{get_token_account_mint, parse_token, TokenAccountType, UiAccountState}, + UiAccountData, + }, + solana_clap_utils::{ + fee_payer::fee_payer_arg, + input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, value_of}, + input_validators::{ + is_amount, is_amount_or_all, is_parsable, is_pubkey, is_url_or_moniker, + is_valid_pubkey, is_valid_signer, }, - confidential_transfer_fee::ConfidentialTransferFeeConfig, - cpi_guard::CpiGuard, - default_account_state::DefaultAccountState, - interest_bearing_mint::InterestBearingConfig, - memo_transfer::MemoTransfer, - metadata_pointer::MetadataPointer, - mint_close_authority::MintCloseAuthority, - permanent_delegate::PermanentDelegate, - transfer_fee::{TransferFeeAmount, TransferFeeConfig}, - transfer_hook::TransferHook, - BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned, + keypair::signer_from_path, + memo::memo_arg, + nonce::*, + offline::{self, *}, + ArgConstant, + }, + solana_cli_output::{ + return_signers_data, CliSignOnlyData, CliSignature, OutputFormat, QuietDisplay, + ReturnSignersConfig, VerboseDisplay, + }, + solana_client::rpc_request::TokenAccountsFilter, + solana_remote_wallet::remote_wallet::RemoteWalletManager, + solana_sdk::{ + instruction::AccountMeta, + native_token::*, + program_option::COption, + pubkey::Pubkey, + signature::{Keypair, Signer}, + system_program, }, - instruction::*, - solana_zk_token_sdk::{ - encryption::{ - auth_encryption::AeKey, - elgamal::{self, ElGamalKeypair}, + spl_associated_token_account::get_associated_token_address_with_program_id, + spl_token_2022::{ + extension::{ + confidential_transfer::{ + account_info::{ + ApplyPendingBalanceAccountInfo, TransferAccountInfo, WithdrawAccountInfo, + }, + instruction::TransferSplitContextStateAccounts, + ConfidentialTransferAccount, ConfidentialTransferMint, + }, + confidential_transfer_fee::ConfidentialTransferFeeConfig, + cpi_guard::CpiGuard, + default_account_state::DefaultAccountState, + interest_bearing_mint::InterestBearingConfig, + memo_transfer::MemoTransfer, + metadata_pointer::MetadataPointer, + mint_close_authority::MintCloseAuthority, + permanent_delegate::PermanentDelegate, + transfer_fee::{TransferFeeAmount, TransferFeeConfig}, + transfer_hook::TransferHook, + BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned, + }, + instruction::*, + solana_zk_token_sdk::{ + encryption::{ + auth_encryption::AeKey, + elgamal::{self, ElGamalKeypair}, + }, + zk_token_elgamal::pod::ElGamalPubkey, }, - zk_token_elgamal::pod::ElGamalPubkey, + state::{Account, AccountState, Mint}, }, - state::{Account, AccountState, Mint}, -}; -use spl_token_client::{ - client::{ProgramRpcClientSendTransaction, RpcClientResponse}, - token::{ExtensionInitializationParams, Token}, -}; -use spl_token_metadata_interface::state::{Field, TokenMetadata}; -use std::{ - collections::HashMap, fmt, fmt::Display, process::exit, rc::Rc, str::FromStr, sync::Arc, + spl_token_client::{ + client::{ProgramRpcClientSendTransaction, RpcClientResponse}, + token::{ExtensionInitializationParams, Token}, + }, + spl_token_metadata_interface::state::{Field, TokenMetadata}, + std::{ + collections::HashMap, + fmt::{self, Display}, + process::exit, + rc::Rc, + str::FromStr, + sync::Arc, + }, + strum::IntoEnumIterator, + strum_macros::{EnumIter, EnumString, IntoStaticStr}, }; -use strum::IntoEnumIterator; -use strum_macros::{EnumIter, EnumString, IntoStaticStr}; mod config; use config::{Config, MintInfo}; diff --git a/token/cli/src/output.rs b/token/cli/src/output.rs index 2d0d0d9d52b..adf928e7192 100644 --- a/token/cli/src/output.rs +++ b/token/cli/src/output.rs @@ -1,18 +1,20 @@ -use crate::{config::Config, sort::UnsupportedAccount}; -use console::{style, Emoji}; -use serde::{Deserialize, Serialize, Serializer}; -use solana_account_decoder::{ - parse_token::{UiAccountState, UiMint, UiMultisig, UiTokenAccount, UiTokenAmount}, - parse_token_extension::{ - UiConfidentialTransferAccount, UiConfidentialTransferFeeAmount, - UiConfidentialTransferFeeConfig, UiConfidentialTransferMint, UiCpiGuard, - UiDefaultAccountState, UiExtension, UiInterestBearingConfig, UiMemoTransfer, - UiMetadataPointer, UiMintCloseAuthority, UiPermanentDelegate, UiTokenMetadata, - UiTransferFeeAmount, UiTransferFeeConfig, UiTransferHook, UiTransferHookAccount, +use { + crate::{config::Config, sort::UnsupportedAccount}, + console::{style, Emoji}, + serde::{Deserialize, Serialize, Serializer}, + solana_account_decoder::{ + parse_token::{UiAccountState, UiMint, UiMultisig, UiTokenAccount, UiTokenAmount}, + parse_token_extension::{ + UiConfidentialTransferAccount, UiConfidentialTransferFeeAmount, + UiConfidentialTransferFeeConfig, UiConfidentialTransferMint, UiCpiGuard, + UiDefaultAccountState, UiExtension, UiInterestBearingConfig, UiMemoTransfer, + UiMetadataPointer, UiMintCloseAuthority, UiPermanentDelegate, UiTokenMetadata, + UiTransferFeeAmount, UiTransferFeeConfig, UiTransferHook, UiTransferHookAccount, + }, }, + solana_cli_output::{display::writeln_name_value, OutputFormat, QuietDisplay, VerboseDisplay}, + std::fmt::{self, Display}, }; -use solana_cli_output::{display::writeln_name_value, OutputFormat, QuietDisplay, VerboseDisplay}; -use std::fmt::{self, Display}; pub(crate) trait Output: Serialize + fmt::Display + QuietDisplay + VerboseDisplay {} diff --git a/token/cli/src/sort.rs b/token/cli/src/sort.rs index 0652f99240d..463e63d72fb 100644 --- a/token/cli/src/sort.rs +++ b/token/cli/src/sort.rs @@ -1,15 +1,17 @@ -use crate::{ - output::{CliTokenAccount, CliTokenAccounts}, - Error, -}; -use serde::{Deserialize, Serialize}; -use solana_account_decoder::{parse_token::TokenAccountType, UiAccountData}; -use solana_client::rpc_response::RpcKeyedAccount; -use solana_sdk::pubkey::Pubkey; -use spl_associated_token_account::get_associated_token_address_with_program_id; -use std::{ - collections::{btree_map::Entry, BTreeMap}, - str::FromStr, +use { + crate::{ + output::{CliTokenAccount, CliTokenAccounts}, + Error, + }, + serde::{Deserialize, Serialize}, + solana_account_decoder::{parse_token::TokenAccountType, UiAccountData}, + solana_client::rpc_response::RpcKeyedAccount, + solana_sdk::pubkey::Pubkey, + spl_associated_token_account::get_associated_token_address_with_program_id, + std::{ + collections::{btree_map::Entry, BTreeMap}, + str::FromStr, + }, }; #[derive(Serialize, Deserialize)] diff --git a/token/client/src/token.rs b/token/client/src/token.rs index f5d467ad04b..0198f3a5de1 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -19,8 +19,10 @@ use { transaction::Transaction, }, spl_associated_token_account::{ - get_associated_token_address_with_program_id, instruction::create_associated_token_account, - instruction::create_associated_token_account_idempotent, + get_associated_token_address_with_program_id, + instruction::{ + create_associated_token_account, create_associated_token_account_idempotent, + }, }, spl_token_2022::{ extension::{ diff --git a/token/program-2022/src/extension/confidential_transfer/ciphertext_extraction.rs b/token/program-2022/src/extension/confidential_transfer/ciphertext_extraction.rs index 660bc417f85..63fbd0888a5 100644 --- a/token/program-2022/src/extension/confidential_transfer/ciphertext_extraction.rs +++ b/token/program-2022/src/extension/confidential_transfer/ciphertext_extraction.rs @@ -24,7 +24,6 @@ use crate::{ }, }, }; - #[cfg(feature = "serde-traits")] use { crate::serialization::decrypthandle_fromstr, diff --git a/token/program-2022/src/extension/confidential_transfer/instruction.rs b/token/program-2022/src/extension/confidential_transfer/instruction.rs index 0e6c23d7f2b..c235f40fffd 100644 --- a/token/program-2022/src/extension/confidential_transfer/instruction.rs +++ b/token/program-2022/src/extension/confidential_transfer/instruction.rs @@ -3,6 +3,11 @@ use solana_zk_token_sdk::encryption::auth_encryption::AeCiphertext; pub use solana_zk_token_sdk::{ zk_token_proof_instruction::*, zk_token_proof_state::ProofContextState, }; +#[cfg(feature = "serde-traits")] +use { + crate::serialization::aeciphertext_fromstr, + serde::{Deserialize, Serialize}, +}; use { crate::{ check_program_account, @@ -20,12 +25,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use { - crate::serialization::aeciphertext_fromstr, - serde::{Deserialize, Serialize}, -}; - /// Confidential Transfer extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/confidential_transfer/processor.rs b/token/program-2022/src/extension/confidential_transfer/processor.rs index a0556415a0d..58c2f3a9413 100644 --- a/token/program-2022/src/extension/confidential_transfer/processor.rs +++ b/token/program-2022/src/extension/confidential_transfer/processor.rs @@ -1,3 +1,9 @@ +// Remove feature once zk ops syscalls are enabled on all networks +#[cfg(feature = "zk-ops")] +use { + crate::extension::non_transferable::NonTransferable, + solana_zk_token_sdk::zk_token_elgamal::ops as syscall, +}; use { crate::{ check_program_account, @@ -26,12 +32,6 @@ use { sysvar::Sysvar, }, }; -// Remove feature once zk ops syscalls are enabled on all networks -#[cfg(feature = "zk-ops")] -use { - crate::extension::non_transferable::NonTransferable, - solana_zk_token_sdk::zk_token_elgamal::ops as syscall, -}; /// Processes an [InitializeMint] instruction. fn process_initialize_mint( diff --git a/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs b/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs index 11831701785..9d79b7bbe4e 100644 --- a/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs +++ b/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs @@ -1,3 +1,8 @@ +#[cfg(feature = "serde-traits")] +use { + crate::serialization::{aeciphertext_fromstr, elgamalpubkey_fromstr}, + serde::{Deserialize, Serialize}, +}; use { crate::{ check_program_account, @@ -24,12 +29,6 @@ use { std::convert::TryFrom, }; -#[cfg(feature = "serde-traits")] -use { - crate::serialization::{aeciphertext_fromstr, elgamalpubkey_fromstr}, - serde::{Deserialize, Serialize}, -}; - /// Confidential Transfer extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/confidential_transfer_fee/processor.rs b/token/program-2022/src/extension/confidential_transfer_fee/processor.rs index e1ee5099371..2e1743afd47 100644 --- a/token/program-2022/src/extension/confidential_transfer_fee/processor.rs +++ b/token/program-2022/src/extension/confidential_transfer_fee/processor.rs @@ -1,3 +1,6 @@ +// Remove feature once zk ops syscalls are enabled on all networks +#[cfg(feature = "zk-ops")] +use solana_zk_token_sdk::zk_token_elgamal::ops as syscall; use { crate::{ check_program_account, check_zk_token_proof_program_account, @@ -41,10 +44,6 @@ use { spl_pod::{bytemuck::pod_from_bytes, optional_keys::OptionalNonZeroPubkey}, }; -// Remove feature once zk ops syscalls are enabled on all networks -#[cfg(feature = "zk-ops")] -use solana_zk_token_sdk::zk_token_elgamal::ops as syscall; - /// Processes an [InitializeConfidentialTransferFeeConfig] instruction. fn process_initialize_confidential_transfer_fee_config( accounts: &[AccountInfo], diff --git a/token/program-2022/src/extension/cpi_guard/instruction.rs b/token/program-2022/src/extension/cpi_guard/instruction.rs index 3293e683f82..fa3ae346d41 100644 --- a/token/program-2022/src/extension/cpi_guard/instruction.rs +++ b/token/program-2022/src/extension/cpi_guard/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -11,9 +13,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// CPI Guard extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/cpi_guard/mod.rs b/token/program-2022/src/extension/cpi_guard/mod.rs index 9c75d8f92aa..7af9bd71153 100644 --- a/token/program-2022/src/extension/cpi_guard/mod.rs +++ b/token/program-2022/src/extension/cpi_guard/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ extension::{BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsMut}, @@ -8,9 +10,6 @@ use { spl_pod::primitives::PodBool, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// CPI Guard extension instructions pub mod instruction; diff --git a/token/program-2022/src/extension/default_account_state/instruction.rs b/token/program-2022/src/extension/default_account_state/instruction.rs index 2bb6931364f..5d49357a24f 100644 --- a/token/program-2022/src/extension/default_account_state/instruction.rs +++ b/token/program-2022/src/extension/default_account_state/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, error::TokenError, instruction::TokenInstruction, @@ -12,9 +14,6 @@ use { std::convert::TryFrom, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Default Account State extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/default_account_state/mod.rs b/token/program-2022/src/extension/default_account_state/mod.rs index 23d14b0677e..939bd16b06f 100644 --- a/token/program-2022/src/extension/default_account_state/mod.rs +++ b/token/program-2022/src/extension/default_account_state/mod.rs @@ -1,11 +1,10 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Default Account state extension instructions pub mod instruction; diff --git a/token/program-2022/src/extension/group_pointer/instruction.rs b/token/program-2022/src/extension/group_pointer/instruction.rs index 331dc119eff..dc630c71cd1 100644 --- a/token/program-2022/src/extension/group_pointer/instruction.rs +++ b/token/program-2022/src/extension/group_pointer/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -14,9 +16,6 @@ use { std::convert::TryInto, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Group pointer extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/group_pointer/mod.rs b/token/program-2022/src/extension/group_pointer/mod.rs index 60f5aec3669..9fe2679a19e 100644 --- a/token/program-2022/src/extension/group_pointer/mod.rs +++ b/token/program-2022/src/extension/group_pointer/mod.rs @@ -1,12 +1,11 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, spl_pod::optional_keys::OptionalNonZeroPubkey, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Instructions for the GroupPointer extension pub mod instruction; /// Instruction processor for the GroupPointer extension diff --git a/token/program-2022/src/extension/immutable_owner.rs b/token/program-2022/src/extension/immutable_owner.rs index 61aa3329d4e..cc323599490 100644 --- a/token/program-2022/src/extension/immutable_owner.rs +++ b/token/program-2022/src/extension/immutable_owner.rs @@ -1,11 +1,10 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Indicates that the Account owner authority cannot be changed #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/interest_bearing_mint/instruction.rs b/token/program-2022/src/extension/interest_bearing_mint/instruction.rs index 7a61125fe84..2221f934ee2 100644 --- a/token/program-2022/src/extension/interest_bearing_mint/instruction.rs +++ b/token/program-2022/src/extension/interest_bearing_mint/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -15,9 +17,6 @@ use { std::convert::TryInto, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Interesting-bearing mint extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/interest_bearing_mint/mod.rs b/token/program-2022/src/extension/interest_bearing_mint/mod.rs index 26b8fb1df50..5bdf05a3dd9 100644 --- a/token/program-2022/src/extension/interest_bearing_mint/mod.rs +++ b/token/program-2022/src/extension/interest_bearing_mint/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, @@ -9,9 +11,6 @@ use { std::convert::TryInto, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Interest-bearing mint extension instructions pub mod instruction; diff --git a/token/program-2022/src/extension/memo_transfer/instruction.rs b/token/program-2022/src/extension/memo_transfer/instruction.rs index a6af5fde0d3..2c276b5c75f 100644 --- a/token/program-2022/src/extension/memo_transfer/instruction.rs +++ b/token/program-2022/src/extension/memo_transfer/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -11,9 +13,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Required Memo Transfers extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/memo_transfer/mod.rs b/token/program-2022/src/extension/memo_transfer/mod.rs index 0c61ca23994..b77fda8f0f7 100644 --- a/token/program-2022/src/extension/memo_transfer/mod.rs +++ b/token/program-2022/src/extension/memo_transfer/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ error::TokenError, @@ -11,9 +13,6 @@ use { spl_pod::primitives::PodBool, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Memo Transfer extension instructions pub mod instruction; diff --git a/token/program-2022/src/extension/metadata_pointer/instruction.rs b/token/program-2022/src/extension/metadata_pointer/instruction.rs index 841052226d0..2c34ffbf2f5 100644 --- a/token/program-2022/src/extension/metadata_pointer/instruction.rs +++ b/token/program-2022/src/extension/metadata_pointer/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -14,9 +16,6 @@ use { std::convert::TryInto, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Metadata pointer extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/metadata_pointer/mod.rs b/token/program-2022/src/extension/metadata_pointer/mod.rs index 2f41bd75642..c14932d5000 100644 --- a/token/program-2022/src/extension/metadata_pointer/mod.rs +++ b/token/program-2022/src/extension/metadata_pointer/mod.rs @@ -1,12 +1,11 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, spl_pod::optional_keys::OptionalNonZeroPubkey, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Instructions for the MetadataPointer extension pub mod instruction; /// Instruction processor for the MetadataPointer extension diff --git a/token/program-2022/src/extension/mint_close_authority.rs b/token/program-2022/src/extension/mint_close_authority.rs index f595d8dc100..7321b7f6004 100644 --- a/token/program-2022/src/extension/mint_close_authority.rs +++ b/token/program-2022/src/extension/mint_close_authority.rs @@ -1,12 +1,11 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, spl_pod::optional_keys::OptionalNonZeroPubkey, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Close authority extension data for mints. #[repr(C)] #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] diff --git a/token/program-2022/src/extension/mod.rs b/token/program-2022/src/extension/mod.rs index 46a43a4562f..bb08b07d90a 100644 --- a/token/program-2022/src/extension/mod.rs +++ b/token/program-2022/src/extension/mod.rs @@ -1,5 +1,7 @@ //! Extensions available to token mints and accounts +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ error::TokenError, @@ -42,9 +44,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Confidential Transfer extension pub mod confidential_transfer; /// Confidential Transfer Fee extension diff --git a/token/program-2022/src/extension/non_transferable.rs b/token/program-2022/src/extension/non_transferable.rs index a6321161f61..c8b6a61cf86 100644 --- a/token/program-2022/src/extension/non_transferable.rs +++ b/token/program-2022/src/extension/non_transferable.rs @@ -1,11 +1,10 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Indicates that the tokens from this mint can't be transfered #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/permanent_delegate.rs b/token/program-2022/src/extension/permanent_delegate.rs index f70e9516be7..cab3862a46a 100644 --- a/token/program-2022/src/extension/permanent_delegate.rs +++ b/token/program-2022/src/extension/permanent_delegate.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::extension::{BaseState, BaseStateWithExtensions, Extension, ExtensionType}, bytemuck::{Pod, Zeroable}, @@ -5,9 +7,6 @@ use { spl_pod::optional_keys::OptionalNonZeroPubkey, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Permanent delegate extension data for mints. #[repr(C)] #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] diff --git a/token/program-2022/src/extension/transfer_fee/instruction.rs b/token/program-2022/src/extension/transfer_fee/instruction.rs index c28de0941be..8ccd7f93a55 100644 --- a/token/program-2022/src/extension/transfer_fee/instruction.rs +++ b/token/program-2022/src/extension/transfer_fee/instruction.rs @@ -1,3 +1,8 @@ +#[cfg(feature = "serde-traits")] +use { + crate::serialization::coption_fromstr, + serde::{Deserialize, Serialize}, +}; use { crate::{check_program_account, error::TokenError, instruction::TokenInstruction}, solana_program::{ @@ -9,12 +14,6 @@ use { std::convert::TryFrom, }; -#[cfg(feature = "serde-traits")] -use { - crate::serialization::coption_fromstr, - serde::{Deserialize, Serialize}, -}; - /// Transfer Fee extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr( diff --git a/token/program-2022/src/extension/transfer_fee/mod.rs b/token/program-2022/src/extension/transfer_fee/mod.rs index 1ea46ac92ce..d31c78f48ae 100644 --- a/token/program-2022/src/extension/transfer_fee/mod.rs +++ b/token/program-2022/src/extension/transfer_fee/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ error::TokenError, @@ -15,9 +17,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Transfer fee extension instructions pub mod instruction; diff --git a/token/program-2022/src/extension/transfer_hook/instruction.rs b/token/program-2022/src/extension/transfer_hook/instruction.rs index 710879c6208..449d25081c7 100644 --- a/token/program-2022/src/extension/transfer_hook/instruction.rs +++ b/token/program-2022/src/extension/transfer_hook/instruction.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ check_program_account, @@ -14,9 +16,6 @@ use { std::convert::TryInto, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Transfer hook extension instructions #[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))] diff --git a/token/program-2022/src/extension/transfer_hook/mod.rs b/token/program-2022/src/extension/transfer_hook/mod.rs index a8f489ac5d8..c7a43f69be2 100644 --- a/token/program-2022/src/extension/transfer_hook/mod.rs +++ b/token/program-2022/src/extension/transfer_hook/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serde-traits")] +use serde::{Deserialize, Serialize}; use { crate::{ extension::{ @@ -10,9 +12,6 @@ use { spl_pod::{optional_keys::OptionalNonZeroPubkey, primitives::PodBool}, }; -#[cfg(feature = "serde-traits")] -use serde::{Deserialize, Serialize}; - /// Instructions for the TransferHook extension pub mod instruction; /// Instruction processor for the TransferHook extension diff --git a/token/program-2022/src/instruction.rs b/token/program-2022/src/instruction.rs index 95dd690de18..d0636314be9 100644 --- a/token/program-2022/src/instruction.rs +++ b/token/program-2022/src/instruction.rs @@ -2,6 +2,12 @@ #![allow(deprecated)] // needed to avoid deprecation warning when generating serde implementation for TokenInstruction +#[cfg(feature = "serde-traits")] +use { + crate::serialization::coption_fromstr, + serde::{Deserialize, Serialize}, + serde_with::{As, DisplayFromStr}, +}; use { crate::{ check_program_account, check_spl_token_program_account, @@ -23,13 +29,6 @@ use { }, }; -#[cfg(feature = "serde-traits")] -use { - crate::serialization::coption_fromstr, - serde::{Deserialize, Serialize}, - serde_with::{As, DisplayFromStr}, -}; - /// Minimum number of multisignature signers (min N) pub const MIN_SIGNERS: usize = 1; /// Maximum number of multisignature signers (max N) diff --git a/token/program-2022/src/lib.rs b/token/program-2022/src/lib.rs index 13077557224..eef7f9b0786 100644 --- a/token/program-2022/src/lib.rs +++ b/token/program-2022/src/lib.rs @@ -21,7 +21,6 @@ pub mod state; mod entrypoint; // Export current sdk types for downstream users building with a different sdk version -pub use solana_program; use solana_program::{ entrypoint::ProgramResult, program_error::ProgramError, @@ -29,7 +28,7 @@ use solana_program::{ pubkey::{Pubkey, PUBKEY_BYTES}, system_program, }; -pub use solana_zk_token_sdk; +pub use {solana_program, solana_zk_token_sdk}; /// Convert the UI representation of a token amount (using the decimals field defined in its mint) /// to the raw amount diff --git a/token/program-2022/src/state.rs b/token/program-2022/src/state.rs index ae08f342446..94bd76980ea 100644 --- a/token/program-2022/src/state.rs +++ b/token/program-2022/src/state.rs @@ -311,8 +311,7 @@ impl GenericTokenAccount for Account { #[cfg(test)] pub(crate) mod test { - use super::*; - use crate::generic_token_account::ACCOUNT_INITIALIZED_INDEX; + use {super::*, crate::generic_token_account::ACCOUNT_INITIALIZED_INDEX}; pub const TEST_MINT: Mint = Mint { mint_authority: COption::Some(Pubkey::new_from_array([1; 32])), diff --git a/token/program/src/entrypoint.rs b/token/program/src/entrypoint.rs index 6d9ad5dab3e..366ee78d012 100644 --- a/token/program/src/entrypoint.rs +++ b/token/program/src/entrypoint.rs @@ -1,9 +1,11 @@ //! Program entrypoint -use crate::{error::TokenError, processor::Processor}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, - pubkey::Pubkey, +use { + crate::{error::TokenError, processor::Processor}, + solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, + pubkey::Pubkey, + }, }; solana_program::entrypoint!(process_instruction); diff --git a/token/program/src/error.rs b/token/program/src/error.rs index 72461a0fb9c..a758d2c9ba7 100644 --- a/token/program/src/error.rs +++ b/token/program/src/error.rs @@ -1,12 +1,14 @@ //! Error types -use num_derive::FromPrimitive; -use solana_program::{ - decode_error::DecodeError, - msg, - program_error::{PrintProgramError, ProgramError}, +use { + num_derive::FromPrimitive, + solana_program::{ + decode_error::DecodeError, + msg, + program_error::{PrintProgramError, ProgramError}, + }, + thiserror::Error, }; -use thiserror::Error; /// Errors that may be returned by the Token program. #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] diff --git a/token/program/src/instruction.rs b/token/program/src/instruction.rs index e798abdea4d..067fde5f332 100644 --- a/token/program/src/instruction.rs +++ b/token/program/src/instruction.rs @@ -1,15 +1,16 @@ //! Instruction types -use crate::{check_program_account, error::TokenError}; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - program_error::ProgramError, - program_option::COption, - pubkey::Pubkey, - sysvar, +use { + crate::{check_program_account, error::TokenError}, + solana_program::{ + instruction::{AccountMeta, Instruction}, + program_error::ProgramError, + program_option::COption, + pubkey::Pubkey, + sysvar, + }, + std::{convert::TryInto, mem::size_of}, }; -use std::convert::TryInto; -use std::mem::size_of; /// Minimum number of multisignature signers (min N) pub const MIN_SIGNERS: usize = 1; diff --git a/token/program/src/native_mint.rs b/token/program/src/native_mint.rs index 0502f9f71e8..37f75555547 100644 --- a/token/program/src/native_mint.rs +++ b/token/program/src/native_mint.rs @@ -8,8 +8,7 @@ solana_program::declare_id!("So11111111111111111111111111111111111111112"); #[cfg(test)] mod tests { - use super::*; - use solana_program::native_token::*; + use {super::*, solana_program::native_token::*}; #[test] fn test_decimals() { diff --git a/token/program/src/processor.rs b/token/program/src/processor.rs index 6c9b0f4fef0..a849382edff 100644 --- a/token/program/src/processor.rs +++ b/token/program/src/processor.rs @@ -1,24 +1,26 @@ //! Program state processor -use crate::{ - amount_to_ui_amount_string_trimmed, - error::TokenError, - instruction::{is_valid_signer_index, AuthorityType, TokenInstruction, MAX_SIGNERS}, - state::{Account, AccountState, Mint, Multisig}, - try_ui_amount_into_amount, -}; -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint::ProgramResult, - msg, - program::set_return_data, - program_error::ProgramError, - program_memory::sol_memcmp, - program_option::COption, - program_pack::{IsInitialized, Pack}, - pubkey::{Pubkey, PUBKEY_BYTES}, - system_program, - sysvar::{rent::Rent, Sysvar}, +use { + crate::{ + amount_to_ui_amount_string_trimmed, + error::TokenError, + instruction::{is_valid_signer_index, AuthorityType, TokenInstruction, MAX_SIGNERS}, + state::{Account, AccountState, Mint, Multisig}, + try_ui_amount_into_amount, + }, + solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + msg, + program::set_return_data, + program_error::ProgramError, + program_memory::sol_memcmp, + program_option::COption, + program_pack::{IsInitialized, Pack}, + pubkey::{Pubkey, PUBKEY_BYTES}, + system_program, + sysvar::{rent::Rent, Sysvar}, + }, }; /// Program state handler. @@ -1028,20 +1030,22 @@ fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> { #[cfg(test)] mod tests { - use super::*; - use crate::instruction::*; - use serial_test::serial; - use solana_program::{ - account_info::IntoAccountInfo, - clock::Epoch, - instruction::Instruction, - program_error::{self, PrintProgramError}, - sysvar::rent, - }; - use solana_sdk::account::{ - create_account_for_test, create_is_signer_account_infos, Account as SolanaAccount, + use { + super::*, + crate::instruction::*, + serial_test::serial, + solana_program::{ + account_info::IntoAccountInfo, + clock::Epoch, + instruction::Instruction, + program_error::{self, PrintProgramError}, + sysvar::rent, + }, + solana_sdk::account::{ + create_account_for_test, create_is_signer_account_infos, Account as SolanaAccount, + }, + std::sync::{Arc, RwLock}, }; - use std::sync::{Arc, RwLock}; lazy_static::lazy_static! { static ref EXPECTED_DATA: Arc>> = Arc::new(RwLock::new(Vec::new())); diff --git a/token/program/src/state.rs b/token/program/src/state.rs index 8723065ff09..062daab6bd6 100644 --- a/token/program/src/state.rs +++ b/token/program/src/state.rs @@ -1,13 +1,15 @@ //! State transition types -use crate::instruction::MAX_SIGNERS; -use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use num_enum::TryFromPrimitive; -use solana_program::{ - program_error::ProgramError, - program_option::COption, - program_pack::{IsInitialized, Pack, Sealed}, - pubkey::{Pubkey, PUBKEY_BYTES}, +use { + crate::instruction::MAX_SIGNERS, + arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}, + num_enum::TryFromPrimitive, + solana_program::{ + program_error::ProgramError, + program_option::COption, + program_pack::{IsInitialized, Pack, Sealed}, + pubkey::{Pubkey, PUBKEY_BYTES}, + }, }; /// Mint data. diff --git a/utils/cgen/src/main.rs b/utils/cgen/src/main.rs index 696d4a50590..d774d562f9e 100644 --- a/utils/cgen/src/main.rs +++ b/utils/cgen/src/main.rs @@ -1,7 +1,6 @@ extern crate cbindgen; -use std::env; -use std::path::Path; +use std::{env, path::Path}; fn token>(crate_dir: P) { let output_file = crate_dir.as_ref().join("inc/token.h");