Skip to content

Commit 64e9eb3

Browse files
feat: use sendTransaction for OIS (#2555)
* feat: use sendTransaction for OIS * remove integration test * fix type * fix format * fix type
1 parent f841dfc commit 64e9eb3

File tree

14 files changed

+31
-282
lines changed

14 files changed

+31
-282
lines changed

Diff for: apps/staking/src/hooks/use-api.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@ const useApiContext = (
195195
publicKey: wallet.publicKey,
196196
signAllTransactions: wallet.signAllTransactions,
197197
signTransaction: wallet.signTransaction,
198+
sendTransaction: wallet.sendTransaction,
198199
},
199200
})
200201
: undefined,
201202
[
202203
wallet.publicKey,
203204
wallet.signAllTransactions,
204205
wallet.signTransaction,
206+
wallet.sendTransaction,
205207
connection,
206208
],
207209
);

Diff for: governance/pyth_staking_sdk/integration-tests/all.test.ts

-129
This file was deleted.

Diff for: governance/pyth_staking_sdk/integration-tests/keypairs/alice.json

-6
This file was deleted.

Diff for: governance/pyth_staking_sdk/integration-tests/keypairs/bob.json

-6
This file was deleted.

Diff for: governance/pyth_staking_sdk/integration-tests/keypairs/localnet-authority.json

-6
This file was deleted.

Diff for: governance/pyth_staking_sdk/integration-tests/keypairs/pyth-mint.json

-6
This file was deleted.

Diff for: governance/pyth_staking_sdk/integration-tests/keys.ts

-9
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Diff for: governance/pyth_staking_sdk/integration-tests/start-validator.ts

-107
This file was deleted.

Diff for: governance/pyth_staking_sdk/src/pyth-staking-client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getAssociatedTokenAddressSync,
1515
getMint,
1616
} from "@solana/spl-token";
17-
import type { AnchorWallet } from "@solana/wallet-adapter-react";
1817
import {
1918
Connection,
2019
PublicKey,
@@ -48,6 +47,7 @@ import type {
4847
VestingSchedule,
4948
} from "./types";
5049
import { PositionState } from "./types";
50+
import type { Staking } from "../types/staking";
5151
import { bigintMax, bigintMin } from "./utils/bigint";
5252
import { convertBigIntToBN, convertBNToBigInt } from "./utils/bn";
5353
import { epochToDate, getCurrentEpoch } from "./utils/clock";
@@ -59,22 +59,22 @@ import {
5959
} from "./utils/position";
6060
import { sendTransaction } from "./utils/transaction";
6161
import { getUnlockSchedule } from "./utils/vesting";
62+
import type { PythStakingWallet } from "./utils/wallet";
6263
import { DummyWallet } from "./utils/wallet";
6364
import * as IntegrityPoolIdl from "../idl/integrity-pool.json";
6465
import * as PublisherCapsIdl from "../idl/publisher-caps.json";
6566
import * as StakingIdl from "../idl/staking.json";
6667
import type { IntegrityPool } from "../types/integrity-pool";
6768
import type { PublisherCaps } from "../types/publisher-caps";
68-
import type { Staking } from "../types/staking";
6969

7070
export type PythStakingClientConfig = {
7171
connection: Connection;
72-
wallet?: AnchorWallet;
72+
wallet?: PythStakingWallet;
7373
};
7474

7575
export class PythStakingClient {
7676
connection: Connection;
77-
wallet: AnchorWallet;
77+
wallet: PythStakingWallet;
7878
provider: AnchorProvider;
7979
stakingProgram: Program<Staking>;
8080
integrityPoolProgram: Program<IntegrityPool>;

Diff for: governance/pyth_staking_sdk/src/utils/transaction.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import {
2-
sendTransactions,
3-
TransactionBuilder,
4-
} from "@pythnetwork/solana-utils";
5-
import type { AnchorWallet } from "@solana/wallet-adapter-react";
1+
import { TransactionBuilder } from "@pythnetwork/solana-utils";
62
import { Connection, TransactionInstruction } from "@solana/web3.js";
73

4+
import type { PythStakingWallet } from "./wallet";
5+
86
export const sendTransaction = async (
97
instructions: TransactionInstruction[],
108
connection: Connection,
11-
wallet: AnchorWallet,
9+
wallet: PythStakingWallet,
1210
) => {
1311
const transactions = await TransactionBuilder.batchIntoVersionedTransactions(
1412
wallet.publicKey,
@@ -20,5 +18,7 @@ export const sendTransaction = async (
2018
{},
2119
);
2220

23-
return sendTransactions(transactions, connection, wallet);
21+
for (const transaction of transactions) {
22+
await wallet.sendTransaction(transaction.tx, connection);
23+
}
2424
};

Diff for: governance/pyth_staking_sdk/src/utils/wallet.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import type { AnchorWallet } from "@solana/wallet-adapter-react";
2-
import { PublicKey } from "@solana/web3.js";
2+
import type { TransactionSignature } from "@solana/web3.js";
3+
import {
4+
Connection,
5+
PublicKey,
6+
Transaction,
7+
VersionedTransaction,
8+
} from "@solana/web3.js";
39

4-
export const DummyWallet: AnchorWallet = {
10+
export type PythStakingWallet = AnchorWallet & {
11+
sendTransaction: (
12+
tx: Transaction | VersionedTransaction,
13+
connection: Connection,
14+
) => Promise<TransactionSignature>;
15+
};
16+
17+
export const DummyWallet: PythStakingWallet = {
518
publicKey: PublicKey.default,
619
signTransaction: () => {
720
throw new Error("Cannot sign transaction without a wallet");
821
},
922
signAllTransactions: () => {
1023
throw new Error("Cannot sign transactions without a wallet");
1124
},
25+
sendTransaction: () => {
26+
throw new Error("Cannot send transaction without a wallet");
27+
},
1228
};

0 commit comments

Comments
 (0)