Skip to content

Commit 7688288

Browse files
authored
Cleanup governance address (#204)
* 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
1 parent 2bddf3d commit 7688288

File tree

14 files changed

+45
-77
lines changed

14 files changed

+45
-77
lines changed

metrics/governance_metrics.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
DEVNET_ENDPOINT,
77
DEVNET_STAKING_ADDRESS,
88
DEVNET_PYTH_MINT,
9-
DEVNET_GOVERNANCE_ADDRESS,
9+
GOVERNANCE_ADDRESS,
1010
PythBalance,
11-
DEVNET_REALM_ID,
11+
REALM_ID,
1212
} from "pyth-staking-api";
1313
import * as wasm from "pyth-staking-wasm";
1414
import { StakeAccount, StakeConnection } from "pyth-staking-api";
@@ -68,14 +68,14 @@ export class Metrics {
6868
const actualRealmConfig = (
6969
await tryGetRealmConfig(
7070
stakeConnection.provider.connection,
71-
DEVNET_GOVERNANCE_ADDRESS,
72-
DEVNET_REALM_ID
71+
GOVERNANCE_ADDRESS(),
72+
REALM_ID
7373
)
7474
).account;
7575

7676
const expectedRealmConfig = {
7777
accountType: 11,
78-
realm: DEVNET_REALM_ID,
78+
realm: REALM_ID,
7979
communityVoterWeightAddin: DEVNET_STAKING_ADDRESS,
8080
maxCommunityVoterWeightAddin: DEVNET_STAKING_ADDRESS,
8181
};
@@ -98,7 +98,7 @@ export class Metrics {
9898
const expectedConfig = {
9999
// bump
100100
// governanceAuthority
101-
pythGovernanceRealm: DEVNET_REALM_ID,
101+
pythGovernanceRealm: REALM_ID,
102102
pythTokenMint: DEVNET_PYTH_MINT,
103103
unlockingDuration: 1,
104104
epochDuration: new BN(3600),

staking/Anchor.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ seeds = true
33

44
[programs.localnet]
55
staking = "sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
6-
governance = "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
6+
governance = "GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
77
chat = "gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET"
88

99
[registry]

staking/app/StakeConnection.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ import {
3434
PROGRAM_VERSION_V2,
3535
withCreateTokenOwnerRecord,
3636
} from "@solana/spl-governance";
37-
import {
38-
DEVNET_ENDPOINT,
39-
DEVNET_GOVERNANCE_ADDRESS,
40-
LOCALNET_GOVERNANCE_ADDRESS,
41-
MAINNET_ENDPOINT,
42-
MAINNET_GOVERNANCE_ADDRESS,
43-
} from "./constants";
37+
import { GOVERNANCE_ADDRESS } from "./constants";
4438
import assert from "assert";
4539
import { PositionAccountJs, Position } from "./PositionAccountJs";
4640
let wasm = wasm2;
@@ -78,12 +72,7 @@ export class StakeConnection {
7872
this.config = config;
7973
this.configAddress = configAddress;
8074
this.votingProductMetadataAccount = votingProductMetadataAccount;
81-
this.governanceAddress =
82-
program.provider.connection.rpcEndpoint === MAINNET_ENDPOINT
83-
? MAINNET_GOVERNANCE_ADDRESS
84-
: program.provider.connection.rpcEndpoint === DEVNET_ENDPOINT
85-
? DEVNET_GOVERNANCE_ADDRESS
86-
: LOCALNET_GOVERNANCE_ADDRESS;
75+
this.governanceAddress = GOVERNANCE_ADDRESS();
8776
}
8877

8978
// creates a program connection and loads the staking config

staking/app/constants.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import { PublicKey } from "@solana/web3.js";
2+
import { wasm } from "./StakeConnection";
23

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

6-
export const MAINNET_GOVERNANCE_ADDRESS = new PublicKey(
7-
"GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
8-
);
9-
export const DEVNET_GOVERNANCE_ADDRESS = new PublicKey(
10-
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
11-
);
12-
export const LOCALNET_GOVERNANCE_ADDRESS = new PublicKey(
13-
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
14-
);
7+
export function GOVERNANCE_ADDRESS() {
8+
return new PublicKey(wasm.Constants.GOVERNANCE_PROGRAM());
9+
}
1510

1611
export const STAKING_ADDRESS = new PublicKey(
1712
"sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
1813
);
1914

20-
export const MAINNET_REALM_ID = new PublicKey(
15+
export const REALM_ID = new PublicKey(
2116
"A1f6LNEymJSSJsEVCL1FSgtS1jA9dNTC4ni8SkmbwQjG"
2217
);
23-
export const LOCALNET_REALM_ID = new PublicKey(
24-
"44xGQELUXXD1TiLEMc73RBnCxeW8XKw27LyJNpt2G8bF"
25-
);
26-
export const DEVNET_REALM_ID = LOCALNET_REALM_ID;
2718

2819
export const MAINNET_PYTH_MINT = new PublicKey(
2920
"3ho8ZM4JVqJzD56FADKdW7NTG5Tv6GiBPFUvyRXMy35Q"

staking/app/deploy/1_create_realm.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ import {
77
import { Transaction, Connection } from "@solana/web3.js";
88
import { BN } from "bn.js";
99

10-
import {
11-
AUTHORITY_KEYPAIR,
12-
PYTH_TOKEN,
13-
GOVERNANCE_PROGRAM,
14-
RPC_NODE,
15-
} from "./mainnet_beta";
10+
import { AUTHORITY_KEYPAIR, PYTH_TOKEN, RPC_NODE } from "./mainnet_beta";
1611

17-
import { STAKING_ADDRESS } from "../constants";
12+
import { STAKING_ADDRESS, GOVERNANCE_ADDRESS } from "../constants";
1813
import { Constants } from "pyth-staking-wasm";
1914
// Actual transaction hash :
2015
// mainnet-beta : 3es1jwFLTwMBSSyVyRJ6kcJK9MmYgoJxBqBLVv6D8iKYJ1Jj2jQ9UA24ZDnJ1jqU3BVvLGMifgaGdhnhsturdtTF
16+
// devnet : NjowaS5ApGYkGr19ge2ikQnggJJ4x8DyMcQu3pyzPPyJJ7orL3CY8FJToAMcupP8uCKh288fpBBEH6yPbqQDjiA
2117

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

2521
await withCreateRealm(
2622
tx.instructions,
27-
GOVERNANCE_PROGRAM, // Address of the governance program
23+
GOVERNANCE_ADDRESS(), // Address of the governance program
2824
PROGRAM_VERSION_V2, // Version of the on-chain governance program
2925
"Pyth Governance", // `name` of the realm
3026
AUTHORITY_KEYPAIR.publicKey, // Address of the realm authority

staking/app/deploy/2_create_governance.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import {
99
import { Transaction, Connection, PublicKey } from "@solana/web3.js";
1010
import { BN } from "bn.js";
1111
import { Constants } from "pyth-staking-wasm";
12-
import {
13-
EPOCH_DURATION,
14-
AUTHORITY_KEYPAIR,
15-
GOVERNANCE_PROGRAM,
16-
RPC_NODE,
17-
REALM,
18-
} from "./mainnet_beta";
12+
import { EPOCH_DURATION, AUTHORITY_KEYPAIR, RPC_NODE } from "./mainnet_beta";
1913

14+
import { GOVERNANCE_ADDRESS, REALM_ID } from "../constants";
2015
// Actual transaction hash :
2116
// mainnet-beta : vjUE28suh1yt42aRtsj8mwYpz4zM17WQo4ujfXCDGQ5WK1z5G2JATYvEduh1vdMt2pT9auVLJnoCQMtiyEP3aYC
17+
// devnet : 3gKKKPGAfV15yV1Ce6Tn9vmwbeRnMHcyrvDxDpPhHAEr6L8VAe4N3rkNizhLGa7cM19xQaJykt6rxjx651fFRqXM
18+
2219
async function main() {
2320
const tx = new Transaction();
2421

@@ -50,9 +47,9 @@ async function main() {
5047

5148
await withCreateGovernance(
5249
tx.instructions,
53-
GOVERNANCE_PROGRAM, // Address of our instance of the governance program
50+
GOVERNANCE_ADDRESS(), // Address of our instance of the governance program
5451
PROGRAM_VERSION_V2, // Version of the onchain program
55-
REALM, // Address of the Pyth realms
52+
REALM_ID, // Address of the Pyth realms
5653
undefined, // This is a generic governance so no initial governed account
5754
governanceConfig,
5855
new PublicKey(0), // The realm authority is creating it, so this doesn't need to be defined

staking/app/deploy/3_init_staking.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
AUTHORITY_KEYPAIR,
66
PYTH_TOKEN,
77
RPC_NODE,
8-
REALM,
98
EPOCH_DURATION,
109
} from "./mainnet_beta";
1110
import { BN } from "bn.js";
12-
import { STAKING_ADDRESS } from "../constants";
11+
import { STAKING_ADDRESS, REALM_ID } from "../constants";
1312

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

2726
const globalConfig = {
2827
governanceAuthority: AUTHORITY_KEYPAIR.publicKey,
29-
pythGovernanceRealm: REALM,
28+
pythGovernanceRealm: REALM_ID,
3029
pythTokenMint: PYTH_TOKEN,
3130
unlockingDuration: 1,
3231
epochDuration: new BN(EPOCH_DURATION),

staking/app/deploy/devnet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
1212
export const PYTH_TOKEN = new PublicKey(
1313
"7Bd6bEH4wHTMmov8D2WTXgxzLJcxJYczqE5NaDtZdhF6"
1414
);
15-
export const GOVERNANCE_PROGRAM = new PublicKey(
16-
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
17-
);
15+
1816
export const REALM = new PublicKey(
1917
"44xGQELUXXD1TiLEMc73RBnCxeW8XKw27LyJNpt2G8bF"
2018
);
2119
export const RPC_NODE = "https://api.devnet.solana.com";
20+
21+
export const EPOCH_DURATION = 3600;

staking/app/deploy/mainnet_beta.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { PublicKey, Keypair } from "@solana/web3.js";
22
import fs from "fs";
33
import { homedir } from "os";
4-
54
export const AUTHORITY_PATH = "/.config/solana/deployer.json";
65
export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
76
new Uint8Array(
@@ -12,12 +11,7 @@ export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
1211
export const PYTH_TOKEN = new PublicKey(
1312
"3ho8ZM4JVqJzD56FADKdW7NTG5Tv6GiBPFUvyRXMy35Q"
1413
);
15-
export const GOVERNANCE_PROGRAM = new PublicKey(
16-
"GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
17-
);
18-
export const REALM = new PublicKey(
19-
"A1f6LNEymJSSJsEVCL1FSgtS1jA9dNTC4ni8SkmbwQjG"
20-
);
14+
2115
export const RPC_NODE = "https://api.mainnet-beta.solana.com";
2216

2317
export const EPOCH_DURATION = 3600 * 24 * 7;

staking/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pyth-staking-api",
3-
"version": "1.3.0",
3+
"version": "1.3.2",
44
"description": "SDK for pyth token staking",
55
"main": "app/index.js",
66
"types": "app/index.d.ts",
@@ -20,7 +20,7 @@
2020
"@solana/spl-token": "^0.1.8",
2121
"@solana/web3.js": "^1.36.0",
2222
"encoding": "^0.1.13",
23-
"pyth-staking-wasm": "0.3.2",
23+
"pyth-staking-wasm": "0.3.3",
2424
"ts-node": "^10.7.0",
2525
"typescript": "^4.3.5"
2626
},

0 commit comments

Comments
 (0)