Skip to content

Commit

Permalink
Fix scripts not working with existing client
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Aug 25, 2024
1 parent dfd86a5 commit 5191fd3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"programs/*"
]
resolver = "2"

[profile.release]
overflow-checks = true
Expand All @@ -15,4 +16,4 @@ codegen-units = 1
[workspace.metadata.dylint]
libraries = [
{ git = "https://github.com/crytic/solana-lints", pattern = "lints/*" },
]
]
10 changes: 9 additions & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ export class SunriseStakeClient {
epochReport.tickets.toNumber()
);

console.log("Previous epoch tickets: ", previousEpochTickets.length);

const previousEpochTicketAccountMetas = previousEpochTickets.map(
(ticket) => ({
pubkey: ticket,
Expand All @@ -563,6 +565,11 @@ export class SunriseStakeClient {
})
);

if (previousEpochTickets.length === 0) {
this.log("No tickets to recover");
return null;
}

type Accounts = Parameters<
ReturnType<typeof this.program.methods.recoverTickets>["accounts"]
>[0];
Expand Down Expand Up @@ -627,6 +634,8 @@ export class SunriseStakeClient {
const { address: epochReportAccountAddress, account: epochReport } =
await getEpochReportAccount(this.config, this.program);

console.log("Epoch report account: ", epochReportAccountAddress.toString());

if (!epochReport) {
// no epoch report account found at all - something went wrong
throw new Error("No epoch report account found during recoverTickets");
Expand Down Expand Up @@ -758,7 +767,6 @@ export class SunriseStakeClient {
"Extractable Yield": `${toSol(details.extractableYield)}`,
"Epoch Report Epoch": `${details.epochReport.epoch.toNumber()}`,
"Current Epoch": `${details.currentEpoch.epoch}`,
"Epoch Report Tickets": `${details.epochReport.tickets.toNumber()}`,
};

Object.keys(report).forEach((key) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ export const findAllTickets = async (

tickets.push(orderUnstakeTicketAccount);
}
// Uncomment to inject one not found by the above script
// tickets.push(new PublicKey("..."));
console.log("found tickets", tickets.map((t) => t.toBase58()).join(", "));
console.log("expected count", expectedCount);

// get the actual accounts (in case they have been closed somehow in the meantime)
// TODO Later add pagination here in case the count is too high for one call
const accountInfos = await connection.getMultipleAccountsInfo(tickets);
Expand Down
10 changes: 5 additions & 5 deletions packages/scripts/recoverTickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {Transaction} from "@solana/web3.js";
return;
}

// const txSig = await client.sendAndConfirmTransaction(
// new Transaction().add(recoverIx)
// );
//
// console.log("Action complete:", txSig)
const txSig = await client.sendAndConfirmTransaction(
new Transaction().add(recoverIx)
);

console.log("Action complete:", txSig)
})().catch(console.error);
11 changes: 4 additions & 7 deletions packages/scripts/resizeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import "./util";
import { AnchorProvider, Program } from "@coral-xyz/anchor";
import BN from "bn.js";
import { SystemProgram } from "@solana/web3.js";
import {
IDL,
SunriseStake,
} from "@sunrisestake/app/src/lib/client/types/sunrise_stake";
import { PROGRAM_ID } from "@sunrisestake/app/src/lib/client/util";
import { SUNRISE_STAKE_STATE } from "@sunrisestake/app/src/lib/constants";
import {IDL, SunriseStake} from "@sunrisestake/client";
import {PROGRAM_ID} from "../client/src/util.js";
import { SUNRISE_STAKE_STATE } from "./util.js";

/**
* USAGE (devnet)
Expand All @@ -25,7 +22,7 @@ console.log("Resizing to", resizeAmount);
await program.methods
.resizeState(new BN(resizeAmount))
.accounts({
state: SUNRISE_STAKE_STATE,
state: SUNRISE_STAKE_STATE.state,
payer: provider.publicKey,
updateAuthority: provider.publicKey,
systemProgram: SystemProgram.programId,
Expand Down
12 changes: 6 additions & 6 deletions packages/scripts/token/updateGSolMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import "../util";
import { SunriseStakeClient } from "@sunrisestake/app/src/lib/client";
import { SunriseStakeClient } from "../../client/src/index.js";
import { getMetadataAddress, metadata, provider, uploadMetadata } from "./util";
import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";
import { findGSolMintAuthority } from "@sunrisestake/app/src/lib/client/util";
import { SUNRISE_STAKE_STATE } from "@sunrisestake/app/src/lib/constants";
import {findGSolMintAuthority} from "../../client/src/util";
import {WalletAdapterNetwork} from "@solana/wallet-adapter-base";

console.log("Updating gSol metadata");

(async () => {
const uri = await uploadMetadata();

const client = await SunriseStakeClient.get(provider, SUNRISE_STAKE_STATE);
const client = await SunriseStakeClient.get(provider, process.env.REACT_APP_SOLANA_NETWORK as WalletAdapterNetwork|| 'devnet');

const [gsolMintAuthority] = findGSolMintAuthority(client.config!);
console.log("gsol mint auth", gsolMintAuthority);

const sunriseStakeState = await client.program.account.state.fetch(
client.stateAddress
client.config!.stateAddress
);

const metadataAddress = getMetadataAddress(sunriseStakeState.gsolMint);

const transactionSignature = await client.program.methods
.updateMetadata(uri, metadata.name, metadata.symbol)
.accounts({
state: client.stateAddress,
state: client.config!.stateAddress,
marinadeState: client.marinade!.config.marinadeStateAddress,
gsolMint: sunriseStakeState.gsolMint,
gsolMintAuthority,
Expand Down
3 changes: 3 additions & 0 deletions packages/scripts/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os from "os";
import {Cluster, clusterApiUrl, PublicKey} from "@solana/web3.js";
import {AnchorProvider} from "@coral-xyz/anchor";
import {Environment} from "@sunrisestake/client";

export const idWallet = os.homedir() + "/.config/solana/id.json";

Expand All @@ -20,3 +21,5 @@ export const readOnlyProvider = (publicKey: PublicKey): AnchorProvider => {
envProvider.opts,
);
}

export const SUNRISE_STAKE_STATE = Environment["mainnet-beta"];
6 changes: 3 additions & 3 deletions packages/scripts/withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SunriseStakeClient } from "../app/src/lib/client/";
import { SunriseStakeClient } from "../client/src/index.js";
import "./util";
import { AnchorProvider } from "@coral-xyz/anchor";
import BN from "bn.js";
import { SUNRISE_STAKE_STATE } from "@sunrisestake/app/src/lib/constants";
import {WalletAdapterNetwork} from "@solana/wallet-adapter-base";

(async () => {
const provider = AnchorProvider.env();

const client = await SunriseStakeClient.get(provider, SUNRISE_STAKE_STATE);
const client = await SunriseStakeClient.get(provider, process.env.REACT_APP_SOLANA_NETWORK as WalletAdapterNetwork|| 'devnet');
const txSig = await client.unstake(new BN(process.argv[2]));

console.log("Withdraw tx sig: ", txSig);
Expand Down
2 changes: 1 addition & 1 deletion programs/sunrise-stake/src/sunrise_spl/withdraw_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use spl_stake_pool::state::StakePool;
/// 10. `[]` Sysvar clock account (required)
/// 11. `[]` Pool token program id
/// 12. `[]` Stake program id,
/// userdata: amount of pool tokens to withdraw
/// userdata: amount of pool tokens to withdraw

#[derive(Accounts)]
pub struct SplWithdrawStake<'info> {
Expand Down

0 comments on commit 5191fd3

Please sign in to comment.