Skip to content

Commit

Permalink
Cleanup governance address (#204)
Browse files Browse the repository at this point in the history
* Export governance constant in wasm

* Cleanup governance address

* Cleanup governance address consts

* Cleanup

* Cleanup

* Bump, will release when merged

* Cleanup realm id

* Update scripts

* Fix Realm id constant
  • Loading branch information
guibescos authored Oct 20, 2022
1 parent 2bddf3d commit 7688288
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 77 deletions.
12 changes: 6 additions & 6 deletions metrics/governance_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
DEVNET_ENDPOINT,
DEVNET_STAKING_ADDRESS,
DEVNET_PYTH_MINT,
DEVNET_GOVERNANCE_ADDRESS,
GOVERNANCE_ADDRESS,
PythBalance,
DEVNET_REALM_ID,
REALM_ID,
} from "pyth-staking-api";
import * as wasm from "pyth-staking-wasm";
import { StakeAccount, StakeConnection } from "pyth-staking-api";
Expand Down Expand Up @@ -68,14 +68,14 @@ export class Metrics {
const actualRealmConfig = (
await tryGetRealmConfig(
stakeConnection.provider.connection,
DEVNET_GOVERNANCE_ADDRESS,
DEVNET_REALM_ID
GOVERNANCE_ADDRESS(),
REALM_ID
)
).account;

const expectedRealmConfig = {
accountType: 11,
realm: DEVNET_REALM_ID,
realm: REALM_ID,
communityVoterWeightAddin: DEVNET_STAKING_ADDRESS,
maxCommunityVoterWeightAddin: DEVNET_STAKING_ADDRESS,
};
Expand All @@ -98,7 +98,7 @@ export class Metrics {
const expectedConfig = {
// bump
// governanceAuthority
pythGovernanceRealm: DEVNET_REALM_ID,
pythGovernanceRealm: REALM_ID,
pythTokenMint: DEVNET_PYTH_MINT,
unlockingDuration: 1,
epochDuration: new BN(3600),
Expand Down
2 changes: 1 addition & 1 deletion staking/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ seeds = true

[programs.localnet]
staking = "sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
governance = "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
governance = "GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
chat = "gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET"

[registry]
Expand Down
15 changes: 2 additions & 13 deletions staking/app/StakeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ import {
PROGRAM_VERSION_V2,
withCreateTokenOwnerRecord,
} from "@solana/spl-governance";
import {
DEVNET_ENDPOINT,
DEVNET_GOVERNANCE_ADDRESS,
LOCALNET_GOVERNANCE_ADDRESS,
MAINNET_ENDPOINT,
MAINNET_GOVERNANCE_ADDRESS,
} from "./constants";
import { GOVERNANCE_ADDRESS } from "./constants";
import assert from "assert";
import { PositionAccountJs, Position } from "./PositionAccountJs";
let wasm = wasm2;
Expand Down Expand Up @@ -78,12 +72,7 @@ export class StakeConnection {
this.config = config;
this.configAddress = configAddress;
this.votingProductMetadataAccount = votingProductMetadataAccount;
this.governanceAddress =
program.provider.connection.rpcEndpoint === MAINNET_ENDPOINT
? MAINNET_GOVERNANCE_ADDRESS
: program.provider.connection.rpcEndpoint === DEVNET_ENDPOINT
? DEVNET_GOVERNANCE_ADDRESS
: LOCALNET_GOVERNANCE_ADDRESS;
this.governanceAddress = GOVERNANCE_ADDRESS();
}

// creates a program connection and loads the staking config
Expand Down
19 changes: 5 additions & 14 deletions staking/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { PublicKey } from "@solana/web3.js";
import { wasm } from "./StakeConnection";

export const MAINNET_ENDPOINT = "https://api.mainnet-beta.solana.com";
export const DEVNET_ENDPOINT = "https://api.devnet.solana.com";

export const MAINNET_GOVERNANCE_ADDRESS = new PublicKey(
"GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
);
export const DEVNET_GOVERNANCE_ADDRESS = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);
export const LOCALNET_GOVERNANCE_ADDRESS = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);
export function GOVERNANCE_ADDRESS() {
return new PublicKey(wasm.Constants.GOVERNANCE_PROGRAM());
}

export const STAKING_ADDRESS = new PublicKey(
"sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
);

export const MAINNET_REALM_ID = new PublicKey(
export const REALM_ID = new PublicKey(
"A1f6LNEymJSSJsEVCL1FSgtS1jA9dNTC4ni8SkmbwQjG"
);
export const LOCALNET_REALM_ID = new PublicKey(
"44xGQELUXXD1TiLEMc73RBnCxeW8XKw27LyJNpt2G8bF"
);
export const DEVNET_REALM_ID = LOCALNET_REALM_ID;

export const MAINNET_PYTH_MINT = new PublicKey(
"3ho8ZM4JVqJzD56FADKdW7NTG5Tv6GiBPFUvyRXMy35Q"
Expand Down
12 changes: 4 additions & 8 deletions staking/app/deploy/1_create_realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ import {
import { Transaction, Connection } from "@solana/web3.js";
import { BN } from "bn.js";

import {
AUTHORITY_KEYPAIR,
PYTH_TOKEN,
GOVERNANCE_PROGRAM,
RPC_NODE,
} from "./mainnet_beta";
import { AUTHORITY_KEYPAIR, PYTH_TOKEN, RPC_NODE } from "./mainnet_beta";

import { STAKING_ADDRESS } from "../constants";
import { STAKING_ADDRESS, GOVERNANCE_ADDRESS } from "../constants";
import { Constants } from "pyth-staking-wasm";
// Actual transaction hash :
// mainnet-beta : 3es1jwFLTwMBSSyVyRJ6kcJK9MmYgoJxBqBLVv6D8iKYJ1Jj2jQ9UA24ZDnJ1jqU3BVvLGMifgaGdhnhsturdtTF
// devnet : NjowaS5ApGYkGr19ge2ikQnggJJ4x8DyMcQu3pyzPPyJJ7orL3CY8FJToAMcupP8uCKh288fpBBEH6yPbqQDjiA

async function main() {
const tx = new Transaction();

await withCreateRealm(
tx.instructions,
GOVERNANCE_PROGRAM, // Address of the governance program
GOVERNANCE_ADDRESS(), // Address of the governance program
PROGRAM_VERSION_V2, // Version of the on-chain governance program
"Pyth Governance", // `name` of the realm
AUTHORITY_KEYPAIR.publicKey, // Address of the realm authority
Expand Down
15 changes: 6 additions & 9 deletions staking/app/deploy/2_create_governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import {
import { Transaction, Connection, PublicKey } from "@solana/web3.js";
import { BN } from "bn.js";
import { Constants } from "pyth-staking-wasm";
import {
EPOCH_DURATION,
AUTHORITY_KEYPAIR,
GOVERNANCE_PROGRAM,
RPC_NODE,
REALM,
} from "./mainnet_beta";
import { EPOCH_DURATION, AUTHORITY_KEYPAIR, RPC_NODE } from "./mainnet_beta";

import { GOVERNANCE_ADDRESS, REALM_ID } from "../constants";
// Actual transaction hash :
// mainnet-beta : vjUE28suh1yt42aRtsj8mwYpz4zM17WQo4ujfXCDGQ5WK1z5G2JATYvEduh1vdMt2pT9auVLJnoCQMtiyEP3aYC
// devnet : 3gKKKPGAfV15yV1Ce6Tn9vmwbeRnMHcyrvDxDpPhHAEr6L8VAe4N3rkNizhLGa7cM19xQaJykt6rxjx651fFRqXM

async function main() {
const tx = new Transaction();

Expand Down Expand Up @@ -50,9 +47,9 @@ async function main() {

await withCreateGovernance(
tx.instructions,
GOVERNANCE_PROGRAM, // Address of our instance of the governance program
GOVERNANCE_ADDRESS(), // Address of our instance of the governance program
PROGRAM_VERSION_V2, // Version of the onchain program
REALM, // Address of the Pyth realms
REALM_ID, // Address of the Pyth realms
undefined, // This is a generic governance so no initial governed account
governanceConfig,
new PublicKey(0), // The realm authority is creating it, so this doesn't need to be defined
Expand Down
5 changes: 2 additions & 3 deletions staking/app/deploy/3_init_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
AUTHORITY_KEYPAIR,
PYTH_TOKEN,
RPC_NODE,
REALM,
EPOCH_DURATION,
} from "./mainnet_beta";
import { BN } from "bn.js";
import { STAKING_ADDRESS } from "../constants";
import { STAKING_ADDRESS, REALM_ID } from "../constants";

// Actual transaction hash :
// mainnet-beta : KrWZD8gbH6Afg6suwHrmUi1xDo25rLDqqMAoAdunXmtUmuVk5HZgQvDqxFHC2uidL6TfXSmwKdQnkbnbZc8BZam
Expand All @@ -26,7 +25,7 @@ async function main() {

const globalConfig = {
governanceAuthority: AUTHORITY_KEYPAIR.publicKey,
pythGovernanceRealm: REALM,
pythGovernanceRealm: REALM_ID,
pythTokenMint: PYTH_TOKEN,
unlockingDuration: 1,
epochDuration: new BN(EPOCH_DURATION),
Expand Down
6 changes: 3 additions & 3 deletions staking/app/deploy/devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
export const PYTH_TOKEN = new PublicKey(
"7Bd6bEH4wHTMmov8D2WTXgxzLJcxJYczqE5NaDtZdhF6"
);
export const GOVERNANCE_PROGRAM = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);

export const REALM = new PublicKey(
"44xGQELUXXD1TiLEMc73RBnCxeW8XKw27LyJNpt2G8bF"
);
export const RPC_NODE = "https://api.devnet.solana.com";

export const EPOCH_DURATION = 3600;
8 changes: 1 addition & 7 deletions staking/app/deploy/mainnet_beta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PublicKey, Keypair } from "@solana/web3.js";
import fs from "fs";
import { homedir } from "os";

export const AUTHORITY_PATH = "/.config/solana/deployer.json";
export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
new Uint8Array(
Expand All @@ -12,12 +11,7 @@ export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
export const PYTH_TOKEN = new PublicKey(
"3ho8ZM4JVqJzD56FADKdW7NTG5Tv6GiBPFUvyRXMy35Q"
);
export const GOVERNANCE_PROGRAM = new PublicKey(
"GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
);
export const REALM = new PublicKey(
"A1f6LNEymJSSJsEVCL1FSgtS1jA9dNTC4ni8SkmbwQjG"
);

export const RPC_NODE = "https://api.mainnet-beta.solana.com";

export const EPOCH_DURATION = 3600 * 24 * 7;
4 changes: 2 additions & 2 deletions staking/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pyth-staking-api",
"version": "1.3.0",
"version": "1.3.2",
"description": "SDK for pyth token staking",
"main": "app/index.js",
"types": "app/index.d.ts",
Expand All @@ -20,7 +20,7 @@
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.36.0",
"encoding": "^0.1.13",
"pyth-staking-wasm": "0.3.2",
"pyth-staking-wasm": "0.3.3",
"ts-node": "^10.7.0",
"typescript": "^4.3.5"
},
Expand Down
4 changes: 0 additions & 4 deletions staking/programs/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ mod utils;
pub mod wasm;

declare_id!("sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d");

#[cfg(not(mainnet))]
pub const GOVERNANCE_PROGRAM: Pubkey = pubkey!("GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw");
#[cfg(mainnet)]
pub const GOVERNANCE_PROGRAM: Pubkey = pubkey!("GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV");


Expand Down
8 changes: 7 additions & 1 deletion staking/programs/staking/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use crate::state::positions::{
};
use crate::state::target::TargetMetadata;
use crate::state::vesting::VestingEvent;
use crate::VestingSchedule;
use crate::{
VestingSchedule,
GOVERNANCE_PROGRAM,
};
use anchor_lang::prelude::{
error,
Clock,
Expand Down Expand Up @@ -295,6 +298,9 @@ 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
2 changes: 1 addition & 1 deletion staking/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pyth-staking-wasm",
"description": "Web Assembly files for Pyth staking",
"version": "0.3.2",
"version": "0.3.3",
"files": [
"bundle/staking_bg.wasm",
"bundle/staking.js",
Expand Down
10 changes: 5 additions & 5 deletions staking/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

"@solana/[email protected]":
version "0.3.15"
resolved "https://registry.yarnpkg.com/@solana/spl-governance/-/spl-governance-0.3.15.tgz#4fd8b016394dbe6161009209b1521d4fe3b97791"
resolved "https://registry.npmjs.org/@solana/spl-governance/-/spl-governance-0.3.15.tgz"
integrity sha512-VSrzmIXGq5hlCm1JHFCIJGJ2fujqH3GVstyDNTvquxMZioWckmDO5Q/X9oSDft7sziY12tkOW9FDA3Z5m45hBg==
dependencies:
"@solana/web3.js" "^1.22.0"
Expand Down Expand Up @@ -1381,10 +1381,10 @@ prettier@^2.6.2:
resolved "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz"
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==

[email protected].2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/pyth-staking-wasm/-/pyth-staking-wasm-0.3.2.tgz#56c67e63797bb9d7cd4a546bdc80d47174ee6940"
integrity sha512-hfUVBJDLZK+HWAH9m1DnPyWUc9d/Nce5Okc5h1OulsoDQ9taAJBgsQr8UACnNXupoTYBlykfwUFTJ6cnxd0FEw==
[email protected].3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/pyth-staking-wasm/-/pyth-staking-wasm-0.3.3.tgz#fe6d70ff02efe1857aba99fc4a376c3b840a7a55"
integrity sha512-9i5l5N9YHzhZDo5lDJQh8797nYS4e3Mn65yXb+Ksp/J+iUzBEwHenPIHsv+/g9bzTadxr9+pvb3RsC/oWwJf8Q==

randombytes@^2.1.0:
version "2.1.0"
Expand Down

1 comment on commit 7688288

@vercel
Copy link

@vercel vercel bot commented on 7688288 Oct 21, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

staking – ./

staking-rho-nine.vercel.app
staking-pyth-web.vercel.app
staking-git-master-pyth-web.vercel.app

Please sign in to comment.