Skip to content

Commit

Permalink
Update stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Oct 16, 2023
1 parent 0d0a705 commit f92af94
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 42 deletions.
5 changes: 2 additions & 3 deletions staking/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PublicKey } from "@solana/web3.js";
import { wasm } from "./StakeConnection";

export function GOVERNANCE_ADDRESS() {
return new PublicKey(wasm.Constants.GOVERNANCE_PROGRAM());
export function GOVERNANCE_ADDRESS(): PublicKey {
return new PublicKey("pytGY6tWRgGinSCvRLnSv4fHfBTMoiDGiCsesmHWM6U");
}

export const STAKING_ADDRESS = new PublicKey(
Expand Down
12 changes: 3 additions & 9 deletions staking/programs/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

use {
crate::error::ErrorCode,
anchor_lang::{
prelude::*,
solana_program::pubkey,
},
anchor_lang::prelude::*,
anchor_spl::token::transfer,
context::*,
spl_governance::state::{
Expand Down Expand Up @@ -51,9 +48,6 @@ mod utils;
pub mod wasm;

declare_id!("pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ");
pub const GOVERNANCE_PROGRAM: Pubkey = pubkey!("pytGY6tWRgGinSCvRLnSv4fHfBTMoiDGiCsesmHWM6U");


#[program]
pub mod staking {

Expand Down Expand Up @@ -433,7 +427,7 @@ pub mod staking {
.ok_or_else(|| error!(ErrorCode::NoRemainingAccount))?;

let proposal_data: ProposalV2 =
get_proposal_data(&GOVERNANCE_PROGRAM, proposal_account)?;
get_proposal_data(&config.governance_program, proposal_account)?;

let proposal_start = proposal_data
.voting_at
Expand All @@ -455,7 +449,7 @@ pub mod staking {
.ok_or_else(|| error!(ErrorCode::NoRemainingAccount))?;

let governance_data = get_governance_data_for_realm(
&GOVERNANCE_PROGRAM,
&config.governance_program,
governance_account,
&config.pyth_governance_realm,
)?;
Expand Down
4 changes: 0 additions & 4 deletions staking/programs/staking/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
vesting::VestingEvent,
},
VestingSchedule,
GOVERNANCE_PROGRAM,
},
anchor_lang::{
prelude::{
Expand Down Expand Up @@ -316,9 +315,6 @@ impl Constants {
pub fn POSITION_BUFFER_SIZE() -> usize {
crate::state::positions::POSITION_BUFFER_SIZE
}
pub fn GOVERNANCE_PROGRAM() -> js_sys::JsString {
GOVERNANCE_PROGRAM.to_string().into()
}
}

#[wasm_bindgen]
Expand Down
10 changes: 6 additions & 4 deletions staking/target/idl/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,10 @@
"type": "u8"
},
{
"name": "creationEpoch",
"type": "u64"
"name": "transferEpoch",
"type": {
"option": "u64"
}
}
]
}
Expand Down Expand Up @@ -1483,8 +1485,8 @@
},
{
"code": 6028,
"name": "VoteCreationEpoch",
"msg": "Can't vote on the creation epoch"
"name": "VoteDuringTransferEpoch",
"msg": "Can't vote during an account's transfer epoch"
},
{
"code": 6029,
Expand Down
20 changes: 12 additions & 8 deletions staking/target/types/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,10 @@ export type Staking = {
"type": "u8"
},
{
"name": "creationEpoch",
"type": "u64"
"name": "transferEpoch",
"type": {
"option": "u64"
}
}
]
}
Expand Down Expand Up @@ -1483,8 +1485,8 @@ export type Staking = {
},
{
"code": 6028,
"name": "VoteCreationEpoch",
"msg": "Can't vote on the creation epoch"
"name": "VoteDuringTransferEpoch",
"msg": "Can't vote during an account's transfer epoch"
},
{
"code": 6029,
Expand Down Expand Up @@ -2483,8 +2485,10 @@ export const IDL: Staking = {
"type": "u8"
},
{
"name": "creationEpoch",
"type": "u64"
"name": "transferEpoch",
"type": {
"option": "u64"
}
}
]
}
Expand Down Expand Up @@ -2979,8 +2983,8 @@ export const IDL: Staking = {
},
{
"code": 6028,
"name": "VoteCreationEpoch",
"msg": "Can't vote on the creation epoch"
"name": "VoteDuringTransferEpoch",
"msg": "Can't vote during an account's transfer epoch"
},
{
"code": 6029,
Expand Down
4 changes: 2 additions & 2 deletions staking/tests/api_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Keypair } from "@solana/web3.js";
import { Keypair, PublicKey } from "@solana/web3.js";
import assert from "assert";
import { StakeConnection } from "../app/StakeConnection";
import {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("api", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey),
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique()),
PythBalance.fromString("1000")
));

Expand Down
4 changes: 2 additions & 2 deletions staking/tests/clock_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
standardSetup,
} from "./utils/before";
import path from "path";
import { Keypair } from "@solana/web3.js";
import { Keypair, PublicKey } from "@solana/web3.js";
import { StakeConnection } from "../app";
import assert from "assert";
import { BN } from "@project-serum/anchor";
Expand All @@ -33,7 +33,7 @@ describe("clock_api", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));
});

Expand Down
5 changes: 4 additions & 1 deletion staking/tests/create_product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe("create_product", async () => {

before(async () => {
const config = readAnchorConfig(ANCHOR_CONFIG_PATH);
let globalConfig = makeDefaultConfig(pythMintAccount.publicKey);
let globalConfig = makeDefaultConfig(
pythMintAccount.publicKey,
PublicKey.unique()
);

({ controller, stakeConnection } = await standardSetup(
portNumber,
Expand Down
2 changes: 1 addition & 1 deletion staking/tests/max_pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("fills a stake account with positions", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));
program = stakeConnection.program;
provider = stakeConnection.provider;
Expand Down
2 changes: 1 addition & 1 deletion staking/tests/position_lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("position_lifecycle", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));
program = stakeConnection.program;
owner = stakeConnection.provider.wallet.publicKey;
Expand Down
4 changes: 2 additions & 2 deletions staking/tests/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("staking", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));
program = stakeConnection.program;
provider = stakeConnection.provider;
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("staking", async () => {
owner,
lock: { fullyVested: {} },
nextIndex: 0,
creationEpoch: new BN(0),
transferEpoch: null,
})
);
});
Expand Down
2 changes: 1 addition & 1 deletion staking/tests/unlock_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("unlock_api", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));

EPOCH_DURATION = stakeConnection.config.epochDuration;
Expand Down
7 changes: 6 additions & 1 deletion staking/tests/utils/before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ export async function initConfig(
});
}

export function makeDefaultConfig(pythMint: PublicKey): GlobalConfig {
export function makeDefaultConfig(
pythMint: PublicKey,
governanceProgram: PublicKey
): GlobalConfig {
return {
governanceAuthority: null,
pythGovernanceRealm: null,
Expand All @@ -333,6 +336,8 @@ export function makeDefaultConfig(pythMint: PublicKey): GlobalConfig {
mockClockTime: new BN(10),
bump: 0,
pythTokenListTime: null,
governanceProgram,
pdaAuthority: PublicKey.unique(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion staking/tests/vesting_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("vesting", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(pythMintAccount.publicKey, PublicKey.unique())
));

EPOCH_DURATION = stakeConnection.config.epochDuration;
Expand Down
5 changes: 4 additions & 1 deletion staking/tests/voter_weight_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ describe("voter_weight_test", async () => {
config,
pythMintAccount,
pythMintAuthority,
makeDefaultConfig(pythMintAccount.publicKey)
makeDefaultConfig(
pythMintAccount.publicKey,
new PublicKey(config.programs.localnet.governance)
)
));

EPOCH_DURATION = stakeConnection.config.epochDuration;
Expand Down
5 changes: 4 additions & 1 deletion staking/tests/voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ describe("voting", async () => {
const config = readAnchorConfig(ANCHOR_CONFIG_PATH);
governanceProgram = new PublicKey(config.programs.localnet.governance);

let defaultConfig = makeDefaultConfig(pythMintAccount.publicKey);
let defaultConfig = makeDefaultConfig(
pythMintAccount.publicKey,
governanceProgram
);
defaultConfig.epochDuration = new BN(60);
({ controller, stakeConnection } = await standardSetup(
portNumber,
Expand Down

0 comments on commit f92af94

Please sign in to comment.