From 5191fd39b65e22d3060f910d23fa8c448a1d5317 Mon Sep 17 00:00:00 2001 From: dankelleher Date: Sun, 25 Aug 2024 09:19:56 +0200 Subject: [PATCH] Fix scripts not working with existing client --- Cargo.toml | 3 ++- packages/client/src/index.ts | 10 +++++++++- packages/client/src/util.ts | 5 +++++ packages/scripts/recoverTickets.ts | 10 +++++----- packages/scripts/resizeState.ts | 11 ++++------- packages/scripts/token/updateGSolMetadata.ts | 12 ++++++------ packages/scripts/util.ts | 3 +++ packages/scripts/withdraw.ts | 6 +++--- .../sunrise-stake/src/sunrise_spl/withdraw_stake.rs | 2 +- 9 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 82c5a9b4..3f15b53a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "programs/*" ] +resolver = "2" [profile.release] overflow-checks = true @@ -15,4 +16,4 @@ codegen-units = 1 [workspace.metadata.dylint] libraries = [ { git = "https://github.com/crytic/solana-lints", pattern = "lints/*" }, -] \ No newline at end of file +] diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 9d92c264..333bdf9c 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -555,6 +555,8 @@ export class SunriseStakeClient { epochReport.tickets.toNumber() ); + console.log("Previous epoch tickets: ", previousEpochTickets.length); + const previousEpochTicketAccountMetas = previousEpochTickets.map( (ticket) => ({ pubkey: ticket, @@ -563,6 +565,11 @@ export class SunriseStakeClient { }) ); + if (previousEpochTickets.length === 0) { + this.log("No tickets to recover"); + return null; + } + type Accounts = Parameters< ReturnType["accounts"] >[0]; @@ -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"); @@ -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) => { diff --git a/packages/client/src/util.ts b/packages/client/src/util.ts index 21fce06d..39656bb0 100644 --- a/packages/client/src/util.ts +++ b/packages/client/src/util.ts @@ -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); diff --git a/packages/scripts/recoverTickets.ts b/packages/scripts/recoverTickets.ts index 101529c6..fbd0a0ce 100644 --- a/packages/scripts/recoverTickets.ts +++ b/packages/scripts/recoverTickets.ts @@ -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); diff --git a/packages/scripts/resizeState.ts b/packages/scripts/resizeState.ts index cc4726f1..5c82023a 100644 --- a/packages/scripts/resizeState.ts +++ b/packages/scripts/resizeState.ts @@ -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) @@ -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, diff --git a/packages/scripts/token/updateGSolMetadata.ts b/packages/scripts/token/updateGSolMetadata.ts index 44fd1266..1a15bf94 100644 --- a/packages/scripts/token/updateGSolMetadata.ts +++ b/packages/scripts/token/updateGSolMetadata.ts @@ -1,23 +1,23 @@ /* 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); @@ -25,7 +25,7 @@ console.log("Updating gSol metadata"); 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, diff --git a/packages/scripts/util.ts b/packages/scripts/util.ts index 8e482192..cef43673 100644 --- a/packages/scripts/util.ts +++ b/packages/scripts/util.ts @@ -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"; @@ -20,3 +21,5 @@ export const readOnlyProvider = (publicKey: PublicKey): AnchorProvider => { envProvider.opts, ); } + +export const SUNRISE_STAKE_STATE = Environment["mainnet-beta"]; diff --git a/packages/scripts/withdraw.ts b/packages/scripts/withdraw.ts index 1ee3932e..7c3e6634 100644 --- a/packages/scripts/withdraw.ts +++ b/packages/scripts/withdraw.ts @@ -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); diff --git a/programs/sunrise-stake/src/sunrise_spl/withdraw_stake.rs b/programs/sunrise-stake/src/sunrise_spl/withdraw_stake.rs index 2aa2d8a8..ba70fc25 100644 --- a/programs/sunrise-stake/src/sunrise_spl/withdraw_stake.rs +++ b/programs/sunrise-stake/src/sunrise_spl/withdraw_stake.rs @@ -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> {