diff --git a/metrics/governance_metrics.ts b/metrics/governance_metrics.ts index 92bc1029..77db6adb 100644 --- a/metrics/governance_metrics.ts +++ b/metrics/governance_metrics.ts @@ -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"; @@ -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, }; @@ -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), diff --git a/staking/Anchor.toml b/staking/Anchor.toml index 27892f2d..a5a6afe4 100644 --- a/staking/Anchor.toml +++ b/staking/Anchor.toml @@ -3,7 +3,7 @@ seeds = true [programs.localnet] staking = "sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d" -governance = "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw" +governance = "GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV" chat = "gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET" [registry] diff --git a/staking/app/StakeConnection.ts b/staking/app/StakeConnection.ts index 746f385e..262bb151 100644 --- a/staking/app/StakeConnection.ts +++ b/staking/app/StakeConnection.ts @@ -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; @@ -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 diff --git a/staking/app/constants.ts b/staking/app/constants.ts index a38daabd..c74e3d80 100644 --- a/staking/app/constants.ts +++ b/staking/app/constants.ts @@ -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" diff --git a/staking/app/deploy/1_create_realm.ts b/staking/app/deploy/1_create_realm.ts index 0a4226ce..4c60b2a1 100644 --- a/staking/app/deploy/1_create_realm.ts +++ b/staking/app/deploy/1_create_realm.ts @@ -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 diff --git a/staking/app/deploy/2_create_governance.ts b/staking/app/deploy/2_create_governance.ts index c52f11e2..ef2f88b2 100644 --- a/staking/app/deploy/2_create_governance.ts +++ b/staking/app/deploy/2_create_governance.ts @@ -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(); @@ -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 diff --git a/staking/app/deploy/3_init_staking.ts b/staking/app/deploy/3_init_staking.ts index 84788f37..b5001c18 100644 --- a/staking/app/deploy/3_init_staking.ts +++ b/staking/app/deploy/3_init_staking.ts @@ -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 @@ -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), diff --git a/staking/app/deploy/devnet.ts b/staking/app/deploy/devnet.ts index 19ee1510..94b2344d 100644 --- a/staking/app/deploy/devnet.ts +++ b/staking/app/deploy/devnet.ts @@ -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; diff --git a/staking/app/deploy/mainnet_beta.ts b/staking/app/deploy/mainnet_beta.ts index fc28cf31..4ceb7b17 100644 --- a/staking/app/deploy/mainnet_beta.ts +++ b/staking/app/deploy/mainnet_beta.ts @@ -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( @@ -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; diff --git a/staking/package.json b/staking/package.json index 6306a833..ca3a99be 100644 --- a/staking/package.json +++ b/staking/package.json @@ -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", @@ -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" }, diff --git a/staking/programs/staking/src/lib.rs b/staking/programs/staking/src/lib.rs index 40c20863..ac6b93e6 100644 --- a/staking/programs/staking/src/lib.rs +++ b/staking/programs/staking/src/lib.rs @@ -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"); diff --git a/staking/programs/staking/src/wasm.rs b/staking/programs/staking/src/wasm.rs index aa134ea2..ac6f967a 100644 --- a/staking/programs/staking/src/wasm.rs +++ b/staking/programs/staking/src/wasm.rs @@ -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, @@ -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] diff --git a/staking/wasm/package.json b/staking/wasm/package.json index 8ecd0645..4162f19f 100644 --- a/staking/wasm/package.json +++ b/staking/wasm/package.json @@ -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", diff --git a/staking/yarn.lock b/staking/yarn.lock index 051bdae0..7382fcca 100644 --- a/staking/yarn.lock +++ b/staking/yarn.lock @@ -79,7 +79,7 @@ "@solana/spl-governance@0.3.15": 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" @@ -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== -pyth-staking-wasm@0.3.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== +pyth-staking-wasm@0.3.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"