Skip to content

Commit

Permalink
Cleanup staking address, now it is the same across all 3 networks (#203)
Browse files Browse the repository at this point in the history
* Cleanup staking address, now it is the same across all 3 networks

* Cleanup

* Cleanup
  • Loading branch information
guibescos authored Oct 20, 2022
1 parent 92bd040 commit 2bddf3d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 58 deletions.
2 changes: 1 addition & 1 deletion staking/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
seeds = true

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

Expand Down
11 changes: 3 additions & 8 deletions staking/app/PythClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnchorProvider, Wallet } from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import { DEVNET_STAKING_ADDRESS, LOCALNET_STAKING_ADDRESS } from "./constants";
import { STAKING_ADDRESS } from "./constants";
import { StakeConnection } from "./StakeConnection";

export class PythClient {
Expand All @@ -9,10 +9,7 @@ export class PythClient {
constructor(public stakeConnection: StakeConnection, cluster: string) {
this.cluster = cluster;
this.program = {
programId:
cluster === "localnet"
? LOCALNET_STAKING_ADDRESS
: DEVNET_STAKING_ADDRESS,
programId: STAKING_ADDRESS,
};
}
static async connect(
Expand All @@ -25,9 +22,7 @@ export class PythClient {
await StakeConnection.createStakeConnection(
provider.connection,
provider.wallet as unknown as Wallet,
cluster === "localnet"
? LOCALNET_STAKING_ADDRESS
: DEVNET_STAKING_ADDRESS
STAKING_ADDRESS
),
cluster
);
Expand Down
9 changes: 1 addition & 8 deletions staking/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ export const LOCALNET_GOVERNANCE_ADDRESS = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);

export const MAINNET_STAKING_ADDRESS = new PublicKey(
"sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
);
export const LOCALNET_STAKING_ADDRESS = new PublicKey(
"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
);

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

Expand Down
6 changes: 3 additions & 3 deletions staking/app/deploy/1_create_realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { BN } from "bn.js";
import {
AUTHORITY_KEYPAIR,
PYTH_TOKEN,
STAKING_PROGRAM,
GOVERNANCE_PROGRAM,
RPC_NODE,
} from "./mainnet_beta";

import { STAKING_ADDRESS } from "../constants";
import { Constants } from "pyth-staking-wasm";
// Actual transaction hash :
// mainnet-beta : 3es1jwFLTwMBSSyVyRJ6kcJK9MmYgoJxBqBLVv6D8iKYJ1Jj2jQ9UA24ZDnJ1jqU3BVvLGMifgaGdhnhsturdtTF
Expand All @@ -36,8 +36,8 @@ async function main() {
Constants.MAX_VOTER_WEIGHT().toString() // Create governance requires realm authority
),
{
voterWeightAddin: STAKING_PROGRAM, // Voter weight plugin
maxVoterWeightAddin: STAKING_PROGRAM, // Max voter weight plugin
voterWeightAddin: STAKING_ADDRESS, // Voter weight plugin
maxVoterWeightAddin: STAKING_ADDRESS, // Max voter weight plugin
tokenType: GoverningTokenType.Liquid, // Liquid token
},
undefined // No council mint
Expand Down
8 changes: 4 additions & 4 deletions staking/app/deploy/3_init_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { getTargetAccount } from "../../tests/utils/utils";
import {
AUTHORITY_KEYPAIR,
PYTH_TOKEN,
STAKING_PROGRAM,
RPC_NODE,
REALM,
EPOCH_DURATION,
} from "./mainnet_beta";
import { BN } from "bn.js";
import { STAKING_ADDRESS } from "../constants";

// Actual transaction hash :
// mainnet-beta : KrWZD8gbH6Afg6suwHrmUi1xDo25rLDqqMAoAdunXmtUmuVk5HZgQvDqxFHC2uidL6TfXSmwKdQnkbnbZc8BZam
Expand All @@ -21,8 +21,8 @@ async function main() {
new Wallet(AUTHORITY_KEYPAIR),
{}
);
const idl = (await Program.fetchIdl(STAKING_PROGRAM, provider))!;
const program = new Program(idl, STAKING_PROGRAM, provider);
const idl = (await Program.fetchIdl(STAKING_ADDRESS, provider))!;
const program = new Program(idl, STAKING_ADDRESS, provider);

const globalConfig = {
governanceAuthority: AUTHORITY_KEYPAIR.publicKey,
Expand All @@ -35,7 +35,7 @@ async function main() {
await program.methods.initConfig(globalConfig).rpc();

const votingTarget = { voting: {} };
const targetAccount = await getTargetAccount(votingTarget, STAKING_PROGRAM);
const targetAccount = await getTargetAccount(votingTarget, STAKING_ADDRESS);
await program.methods
.createTarget(votingTarget)
.accounts({
Expand Down
16 changes: 4 additions & 12 deletions staking/app/deploy/devnet.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { PublicKey, Keypair } from "@solana/web3.js";
import fs from "fs";
import { homedir } from "os";

export const AUTHORITY_PATH =
"~/.config/solana/upg8KLALUN7ByDHiBu4wEbMDTC6UnSVFSYfTyGfXuzr.json";
export const AUTHORITY_PATH = "/.config/solana/deployer.json";
export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(
fs
.readFileSync(
"/Users/gbescos/.config/solana/upg8KLALUN7ByDHiBu4wEbMDTC6UnSVFSYfTyGfXuzr.json"
)
.toString()
)
JSON.parse(fs.readFileSync(homedir() + AUTHORITY_PATH).toString())
)
);

export const PYTH_TOKEN = new PublicKey(
"7Bd6bEH4wHTMmov8D2WTXgxzLJcxJYczqE5NaDtZdhF6"
);
export const STAKING_PROGRAM = new PublicKey(
"sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
);
export const GOVERNANCE_PROGRAM = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);
Expand Down
4 changes: 0 additions & 4 deletions staking/app/deploy/mainnet_beta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PublicKey, Keypair } from "@solana/web3.js";
import BN from "bn.js";
import fs from "fs";
import { homedir } from "os";

Expand All @@ -13,9 +12,6 @@ export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
export const PYTH_TOKEN = new PublicKey(
"3ho8ZM4JVqJzD56FADKdW7NTG5Tv6GiBPFUvyRXMy35Q"
);
export const STAKING_PROGRAM = new PublicKey(
"sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d"
);
export const GOVERNANCE_PROGRAM = new PublicKey(
"GovFUVGZWWwyoLq8rhnoVWknRFkhDSbQiSoREJ5LiZCV"
);
Expand Down
26 changes: 11 additions & 15 deletions staking/app/scripts/devnet_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LAMPORTS_PER_SOL,
PublicKey,
} from "@solana/web3.js";
import { DEVNET_ENDPOINT, DEVNET_STAKING_ADDRESS } from "../constants";
import { DEVNET_ENDPOINT, STAKING_ADDRESS } from "../constants";
import {
ANCHOR_CONFIG_PATH,
CustomAbortController,
Expand Down Expand Up @@ -160,7 +160,7 @@ async function main() {
);
const bpfAccounts = await getBPFUpgradeableUtilAccounts(
devnet,
DEVNET_STAKING_ADDRESS
STAKING_ADDRESS
);

assert(upgradeAuth.publicKey.equals(bpfAccounts.upgradeAuthority));
Expand All @@ -170,7 +170,7 @@ async function main() {
if (DRY_RUN) {
({ controller, connection } = await launchClonedValidator(
devnet,
DEVNET_STAKING_ADDRESS
STAKING_ADDRESS
));
console.log("Localnet is running");
} else {
Expand Down Expand Up @@ -203,19 +203,19 @@ async function upgradeProgram(
throw new Error("Refusing to deploy binary with mock clock enabled");
}
shell.exec(
`solana program deploy ${soPath} --program-id ${DEVNET_STAKING_ADDRESS.toBase58()} -u ${
`solana program deploy ${soPath} --program-id ${STAKING_ADDRESS.toBase58()} -u ${
connection.rpcEndpoint
} --upgrade-authority ${UPGRADE_AUTH_KEYPAIR_PATH}`
);
console.log("Upgraded program");
const idlAddressKey = await idlAddress(DEVNET_STAKING_ADDRESS);
const idlAddressKey = await idlAddress(STAKING_ADDRESS);
const idlFinished = new Promise((resolve) => {
connection.onAccountChange(idlAddressKey, resolve, "finalized");
});
let idlResult = shell.exec(
`anchor idl upgrade --provider.cluster ${
connection.rpcEndpoint
} --provider.wallet ${UPGRADE_AUTH_KEYPAIR_PATH} --filepath ${idlPath} ${DEVNET_STAKING_ADDRESS.toBase58()}`
} --provider.wallet ${UPGRADE_AUTH_KEYPAIR_PATH} --filepath ${idlPath} ${STAKING_ADDRESS.toBase58()}`
);
console.log("Waiting for IDL: %s", idlResult);
await idlFinished;
Expand All @@ -233,17 +233,17 @@ async function upgradeAccounts(connection: anchor.web3.Connection) {
new anchor.Wallet(feePayer),
{}
);
let idl = await Program.fetchIdl(DEVNET_STAKING_ADDRESS, provider)!;
let idl = await Program.fetchIdl(STAKING_ADDRESS, provider)!;

const program = new Program(
idl,
DEVNET_STAKING_ADDRESS,
STAKING_ADDRESS,
provider
) as unknown as Program<Staking>;
console.log("Downloading accounts");
// Position Data can't be loaded via Anchor
const allPositionAccounts: ToPairAccountInterface[] = (
await connection.getProgramAccounts(DEVNET_STAKING_ADDRESS, {
await connection.getProgramAccounts(STAKING_ADDRESS, {
filters: [{ memcmp: program.coder.accounts.memcmp("positionData") }],
})
).map((e) => {
Expand All @@ -254,16 +254,12 @@ async function upgradeAccounts(connection: anchor.web3.Connection) {
});
const allV1 = await program.account.stakeAccountMetadata.all();
console.log("Accounts downloaded");
const pairs = await pairAccounts(
allPositionAccounts,
allV1,
DEVNET_STAKING_ADDRESS
);
const pairs = await pairAccounts(allPositionAccounts, allV1, STAKING_ADDRESS);
await connection.confirmTransaction(airDropSignature);
const stakeConnection = await StakeConnection.createStakeConnection(
connection,
new anchor.Wallet(feePayer),
DEVNET_STAKING_ADDRESS
STAKING_ADDRESS
);

console.log("%d accounts found in need of upgrade", allV1.length);
Expand Down
3 changes: 0 additions & 3 deletions staking/programs/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ mod utils;
#[cfg(feature = "wasm")]
pub mod wasm;

#[cfg(not(mainnet))]
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[cfg(mainnet)]
declare_id!("sta99txADjRfwHQQMNckb8vUN4jcAAhN2HBMTR2Ah6d");

#[cfg(not(mainnet))]
Expand Down

0 comments on commit 2bddf3d

Please sign in to comment.