Skip to content

feat: use sendTransaction for OIS #2555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/staking/src/hooks/use-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ const useApiContext = (
publicKey: wallet.publicKey,
signAllTransactions: wallet.signAllTransactions,
signTransaction: wallet.signTransaction,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signTransaction and signAllTransactions are not used anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they are not used afaik, but I thought it's better to keep them.

sendTransaction: wallet.sendTransaction,
},
})
: undefined,
[
wallet.publicKey,
wallet.signAllTransactions,
wallet.signTransaction,
wallet.sendTransaction,
connection,
],
);
Expand Down
129 changes: 0 additions & 129 deletions governance/pyth_staking_sdk/integration-tests/all.test.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions governance/pyth_staking_sdk/integration-tests/keys.ts

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
107 changes: 0 additions & 107 deletions governance/pyth_staking_sdk/integration-tests/start-validator.ts

This file was deleted.

8 changes: 4 additions & 4 deletions governance/pyth_staking_sdk/src/pyth-staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
getAssociatedTokenAddressSync,
getMint,
} from "@solana/spl-token";
import type { AnchorWallet } from "@solana/wallet-adapter-react";
import {
Connection,
PublicKey,
Expand Down Expand Up @@ -48,6 +47,7 @@ import type {
VestingSchedule,
} from "./types";
import { PositionState } from "./types";
import type { Staking } from "../types/staking";
import { bigintMax, bigintMin } from "./utils/bigint";
import { convertBigIntToBN, convertBNToBigInt } from "./utils/bn";
import { epochToDate, getCurrentEpoch } from "./utils/clock";
Expand All @@ -59,22 +59,22 @@ import {
} from "./utils/position";
import { sendTransaction } from "./utils/transaction";
import { getUnlockSchedule } from "./utils/vesting";
import type { PythStakingWallet } from "./utils/wallet";
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";
import type { IntegrityPool } from "../types/integrity-pool";
import type { PublisherCaps } from "../types/publisher-caps";
import type { Staking } from "../types/staking";

export type PythStakingClientConfig = {
connection: Connection;
wallet?: AnchorWallet;
wallet?: PythStakingWallet;
};

export class PythStakingClient {
connection: Connection;
wallet: AnchorWallet;
wallet: PythStakingWallet;
provider: AnchorProvider;
stakingProgram: Program<Staking>;
integrityPoolProgram: Program<IntegrityPool>;
Expand Down
14 changes: 7 additions & 7 deletions governance/pyth_staking_sdk/src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
sendTransactions,
TransactionBuilder,
} from "@pythnetwork/solana-utils";
import type { AnchorWallet } from "@solana/wallet-adapter-react";
import { TransactionBuilder } from "@pythnetwork/solana-utils";
import { Connection, TransactionInstruction } from "@solana/web3.js";

import type { PythStakingWallet } from "./wallet";

export const sendTransaction = async (
instructions: TransactionInstruction[],
connection: Connection,
wallet: AnchorWallet,
wallet: PythStakingWallet,
) => {
const transactions = await TransactionBuilder.batchIntoVersionedTransactions(
wallet.publicKey,
Expand All @@ -20,5 +18,7 @@ export const sendTransaction = async (
{},
);

return sendTransactions(transactions, connection, wallet);
for (const transaction of transactions) {
await wallet.sendTransaction(transaction.tx, connection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remind me why the interface needs a connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure tbh, my guess is that some wallets will use this connection to send the tx instead of their own.

}
};
20 changes: 18 additions & 2 deletions governance/pyth_staking_sdk/src/utils/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import type { AnchorWallet } from "@solana/wallet-adapter-react";
import { PublicKey } from "@solana/web3.js";
import type { TransactionSignature } from "@solana/web3.js";
import {
Connection,
PublicKey,
Transaction,
VersionedTransaction,
} from "@solana/web3.js";

export const DummyWallet: AnchorWallet = {
export type PythStakingWallet = AnchorWallet & {
sendTransaction: (
tx: Transaction | VersionedTransaction,
connection: Connection,
) => Promise<TransactionSignature>;
};

export const DummyWallet: PythStakingWallet = {
publicKey: PublicKey.default,
signTransaction: () => {
throw new Error("Cannot sign transaction without a wallet");
},
signAllTransactions: () => {
throw new Error("Cannot sign transactions without a wallet");
},
sendTransaction: () => {
throw new Error("Cannot send transaction without a wallet");
},
};