Browse Source

fix(staking): use dummy wallet that throws error (#1947)

* fix(staking): use dummy wallet that throws error

* fix
Keyvan Khademi 1 năm trước cách đây
mục cha
commit
ee551486da

+ 6 - 4
governance/pyth_staking_sdk/src/pyth-staking-client.ts

@@ -1,6 +1,6 @@
 import * as crypto from "crypto";
 
-import { AnchorProvider, BN, Program, Wallet } from "@coral-xyz/anchor";
+import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
 import {
   getTokenOwnerRecordAddress,
   PROGRAM_VERSION_V2,
@@ -15,7 +15,6 @@ import {
 import type { AnchorWallet } from "@solana/wallet-adapter-react";
 import {
   Connection,
-  Keypair,
   PublicKey,
   SystemProgram,
   Transaction,
@@ -46,6 +45,7 @@ import {
 } from "./utils/position";
 import { sendTransaction } from "./utils/transaction";
 import { getUnlockSchedule } from "./utils/vesting";
+import { DummyWallet } from "./utils/wallet";
 import * as IntegrityPoolIdl from "../idl/integrity-pool.json";
 import * as PublisherCapsIdl from "../idl/publisher-caps.json";
 import * as StakingIdl from "../idl/staking.json";
@@ -67,8 +67,10 @@ export class PythStakingClient {
   publisherCapsProgram: Program<PublisherCaps>;
 
   constructor(config: PythStakingClientConfig) {
-    this.connection = config.connection;
-    this.wallet = config.wallet ?? new Wallet(Keypair.generate());
+    const { connection, wallet = DummyWallet } = config;
+
+    this.connection = connection;
+    this.wallet = wallet;
 
     this.provider = new AnchorProvider(this.connection, this.wallet, {
       skipPreflight: true,

+ 12 - 0
governance/pyth_staking_sdk/src/utils/wallet.ts

@@ -0,0 +1,12 @@
+import type { AnchorWallet } from "@solana/wallet-adapter-react";
+import { PublicKey } from "@solana/web3.js";
+
+export const DummyWallet: AnchorWallet = {
+  publicKey: PublicKey.default,
+  signTransaction: () => {
+    throw new Error("Cannot sign transaction without a wallet");
+  },
+  signAllTransactions: () => {
+    throw new Error("Cannot sign transactions without a wallet");
+  },
+};