Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MTG-823] [MTG-835] Hardcode contract addresses #43

Merged
merged 7 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ jobs:
echo "debug = 0" >> Cargo.toml

- name: Run tests
run: cargo test-sbf
run: cargo test-sbf
6 changes: 3 additions & 3 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ anchor_version = "0.26.0"
solana_version = "1.14.10"

[programs.localnet]
voter_stake_registry = "9XZ7Ku7FYGVk3veKba6BRKTFXoYJyh4b4ZHC6MfaTUE8"
voter_stake_registry = "C62KFt3Ujv4GmgaNRpTzyvkERVW2jPSje7cGaw4L5hAx"

[programs.devnet]
voter_stake_registry = "9XZ7Ku7FYGVk3veKba6BRKTFXoYJyh4b4ZHC6MfaTUE8"
voter_stake_registry = "C62KFt3Ujv4GmgaNRpTzyvkERVW2jPSje7cGaw4L5hAx"

[programs.mainnet]
voter_stake_registry = "9XZ7Ku7FYGVk3veKba6BRKTFXoYJyh4b4ZHC6MfaTUE8"
voter_stake_registry = "C62KFt3Ujv4GmgaNRpTzyvkERVW2jPSje7cGaw4L5hAx"

[provider]
cluster = "devnet"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion program-states/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ readme = "README.md"
crate-type = ["cdylib", "lib"]

[features]
test-sbf = []
no-entrypoint = []
cpi = ["no-entrypoint"]

[dependencies]
anchor-lang = { workspace = true, features = ["init-if-needed"] }
Expand Down
2 changes: 1 addition & 1 deletion program-states/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub mod error;
pub mod state;

// Requires by Anchor to declare accounts in crate
declare_id!("9XZ7Ku7FYGVk3veKba6BRKTFXoYJyh4b4ZHC6MfaTUE8");
declare_id!("C62KFt3Ujv4GmgaNRpTzyvkERVW2jPSje7cGaw4L5hAx");
6 changes: 1 addition & 5 deletions programs/voter-stake-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ doctest = false

[features]
no-entrypoint = []
no-idl = []
cpi = ["no-entrypoint"]
default = []
localnet = []
test-sbf = []

[dependencies]
# a) for deployment use these
Expand All @@ -31,7 +27,7 @@ bytemuck = "1.9.1"
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
spl-governance-addin-api = "0.1.3"
mplx-staking-states = { path="../../program-states" }
mpl-common-constants = { git = "https://github.com/metaplex-foundation/mpl-common-constants", features = ["devnet"] }
mpl-common-constants = { git = "https://github.com/metaplex-foundation/mpl-common-constants", features = ["mainnet"] }
spl-associated-token-account = { version = "^1.0.3", features = ["no-entrypoint"] }

[dev-dependencies]
Expand Down
7 changes: 6 additions & 1 deletion programs/voter-stake-registry/src/cpi_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ use solana_program::{
system_program,
};

#[derive(Debug, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
/// Address:
pub const REWARDS_PROGRAM_ADDRESS: Pubkey = Pubkey::new_from_array([
187, 144, 22, 85, 66, 234, 175, 207, 244, 245, 195, 176, 62, 198, 185, 87, 88, 123, 166, 137,
125, 120, 47, 188, 37, 228, 127, 164, 75, 100, 222, 33,
]);

#[derive(Debug, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
pub enum RewardsInstruction {
/// Creates and initializes a reward pool account
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{clock_unix_timestamp, cpi_instructions, find_mining_address};
use crate::{
clock_unix_timestamp,
cpi_instructions::{self, REWARDS_PROGRAM_ADDRESS},
find_mining_address,
};
use anchor_lang::prelude::*;
use mplx_staking_states::{
error::MplStakingError,
Expand Down Expand Up @@ -61,7 +65,7 @@ pub struct ChangeDelegate<'info> {
pub deposit_mining: UncheckedAccount<'info>,

/// CHECK: Rewards Program account
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
7 changes: 5 additions & 2 deletions programs/voter-stake-registry/src/instructions/claim.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{borsh::BorshDeserialize, cpi_instructions};
use crate::{
borsh::BorshDeserialize,
cpi_instructions::{self, REWARDS_PROGRAM_ADDRESS},
};
use anchor_lang::prelude::*;
use anchor_spl::token::{Token, TokenAccount};
use mpl_common_constants::constants::DAO_PUBKEY;
Expand Down Expand Up @@ -67,7 +70,7 @@ pub struct Claim<'info> {
pub token_program: Program<'info, Token>,

/// CHECK: Rewards Program account
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
4 changes: 2 additions & 2 deletions programs/voter-stake-registry/src/instructions/close_voter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cpi_instructions;
use crate::cpi_instructions::{self, REWARDS_PROGRAM_ADDRESS};
use anchor_lang::prelude::*;
use anchor_spl::token::{self, CloseAccount, Token, TokenAccount};
use bytemuck::bytes_of_mut;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct CloseVoter<'info> {
pub token_program: Program<'info, Token>,

/// CHECK: Rewards Program account
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cpi_instructions;
use crate::cpi_instructions::{self, REWARDS_PROGRAM_ADDRESS};
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token};
use mplx_staking_states::{error::MplStakingError, state::Registrar};
Expand Down Expand Up @@ -59,7 +59,7 @@ pub struct CreateRegistrar<'info> {
pub token_program: Program<'info, Token>,

/// CHECK: Rewards Program account
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{cpi_instructions, voter::VoterWeightRecord};
use crate::{
cpi_instructions::{self, REWARDS_PROGRAM_ADDRESS},
voter::VoterWeightRecord,
};
use anchor_lang::prelude::*;
use mplx_staking_states::{
error::MplStakingError,
Expand Down Expand Up @@ -64,7 +67,7 @@ pub struct CreateVoter<'info> {
pub deposit_mining: UncheckedAccount<'info>,

/// CHECK: Rewards program ID
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
5 changes: 3 additions & 2 deletions programs/voter-stake-registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anchor_lang::prelude::*;
use cpi_instructions::REWARDS_PROGRAM_ADDRESS;
use instructions::*;
use mplx_staking_states::{
error::MplStakingError,
Expand All @@ -15,7 +16,7 @@ mod instructions;
pub mod voter;

// The program address.
declare_id!("9XZ7Ku7FYGVk3veKba6BRKTFXoYJyh4b4ZHC6MfaTUE8");
declare_id!("C62KFt3Ujv4GmgaNRpTzyvkERVW2jPSje7cGaw4L5hAx");
StanChe marked this conversation as resolved.
Show resolved Hide resolved

/// # Introduction
///
Expand Down Expand Up @@ -214,7 +215,7 @@ pub struct Stake<'info> {
pub deposit_mining: UncheckedAccount<'info>,

/// CHECK: Rewards Program account
#[account(executable)]
#[account(executable, address = REWARDS_PROGRAM_ADDRESS)]
pub rewards_program: UncheckedAccount<'info>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn stake_with_delegate() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down
10 changes: 5 additions & 5 deletions programs/voter-stake-registry/tests/close_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn two_the_same_voting_mints_fail() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -163,7 +163,7 @@ async fn zero_ata_passed_instead_of_two() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -306,7 +306,7 @@ async fn one_ata_passed_instead_of_two() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -449,7 +449,7 @@ async fn success() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -607,7 +607,7 @@ async fn wrong_order_of_passed_in_ata() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down
Binary file modified programs/voter-stake-registry/tests/fixtures/mplx_rewards.so
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions programs/voter-stake-registry/tests/program_test/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use solana_sdk::{
signature::{Keypair, Signer},
};
use spl_governance::state::{
proposal, realm::GoverningTokenConfigAccountArgs, realm_config::GoverningTokenType, vote_record,
proposal,
realm::{get_realm_address, GoverningTokenConfigAccountArgs},
realm_config::GoverningTokenType,
vote_record,
};
use std::rc::Rc;

Expand Down Expand Up @@ -55,11 +58,8 @@ impl GovernanceCookie {
payer: &Keypair,
voter_weight_addin: &Pubkey,
) -> GovernanceRealmCookie {
let realm = Pubkey::find_program_address(
&[b"governance".as_ref(), name.as_ref()],
&self.program_id,
)
.0;
let realm = get_realm_address(&self.program_id, name);

let community_token_account = Pubkey::find_program_address(
&[
b"governance".as_ref(),
Expand Down
16 changes: 7 additions & 9 deletions programs/voter-stake-registry/tests/program_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub use addin::*;
pub use cookies::*;
pub use governance::*;
use log::*;
use mpl_common_constants::constants::GOVERNANCE_PROGRAM_ID;
pub use solana::*;
use solana_program::{program_option::COption, program_pack::Pack};
use solana_program_test::*;
Expand Down Expand Up @@ -121,14 +120,11 @@ impl TestContext {
// intentionally set to half the limit, to catch potential problems early
test.set_compute_max_units(120000);

let governance_program_id = Pubkey::from(GOVERNANCE_PROGRAM_ID);
test.add_program(
"spl_governance_3_1_1",
governance_program_id,
processor!(spl_governance::processor::process_instruction),
);
let governance_program_id =
Pubkey::from_str("AEauWRrpn9Cs6GXujzdp1YhMmv2288kBt3SdEcPYEerr").unwrap();
test.add_program("spl_governance_3_1_1", governance_program_id, None);
let rewards_program_id =
Pubkey::from_str("J8oa8UUJBydrTKtCdkvwmQQ27ZFDq54zAxWJY5Ey72Ji").unwrap();
Pubkey::from_str("DdAfv8RS2BS41FRjDX5nLXSmQWrPsdC17sbgD66oKcU8").unwrap();
test.add_program("mplx_rewards", rewards_program_id, None);

// Setup the environment
Expand All @@ -141,7 +137,9 @@ impl TestContext {
unit: 10u64.pow(6) as f64,
base_lot: 100_f64,
quote_lot: 10_f64,
pubkey: Some(Pubkey::new_unique()), //Some(mngo_token::ID),
pubkey: Some(
Pubkey::from_str("METAewgxyPbgwsseH8T16a39CQ5VyVxZi9zXiDPY18m").unwrap(),
),
authority: Keypair::new(),
}, // symbol: "MNGO".to_string()
MintCookie {
Expand Down
2 changes: 1 addition & 1 deletion programs/voter-stake-registry/tests/test_all_deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn test_all_deposits() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down
4 changes: 2 additions & 2 deletions programs/voter-stake-registry/tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn test_basic() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -250,7 +250,7 @@ async fn close_voter_with_locked_tokens_should_fail() -> Result<(), TransportErr
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down
10 changes: 5 additions & 5 deletions programs/voter-stake-registry/tests/test_change_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn change_from_own_delegate_to_new_delegate() -> Result<(), TransportError
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -244,7 +244,7 @@ async fn stake_is_too_little() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -467,7 +467,7 @@ async fn delegate_is_the_same() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -620,7 +620,7 @@ async fn change_from_own_delegate_to_new_delegate_and_back_with_cooldown(
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -858,7 +858,7 @@ async fn change_from_own_delegate_to_new_delegate_and_back_instantly() -> Result
let realm = context
.governance
.create_realm(
"testrealm",
"Metaplex DAO",
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down
Loading
Loading