From 67f0e927942a8ae9773a8a5c110f25d0f4bb22d3 Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Sun, 21 Apr 2024 23:17:06 +0400 Subject: [PATCH] fix compile error by moving node-wallet anchor usage into not-exported file (#257) --- ts/client/src/test/market.ts | 2 +- ts/client/src/test/openOrders.ts | 9 ++------- ts/client/src/test/util.ts | 21 +++++++++++++++++++++ ts/client/src/utils/utils.ts | 22 ---------------------- 4 files changed, 24 insertions(+), 30 deletions(-) create mode 100644 ts/client/src/test/util.ts diff --git a/ts/client/src/test/market.ts b/ts/client/src/test/market.ts index daf27e493..4f69a5192 100644 --- a/ts/client/src/test/market.ts +++ b/ts/client/src/test/market.ts @@ -4,10 +4,10 @@ import { OPENBOOK_PROGRAM_ID, findAccountsByMints, findAllMarkets, - initReadOnlyOpenbookClient, Watcher, sleep, } from '..'; +import { initReadOnlyOpenbookClient } from './util'; async function testFindAccountsByMints(): Promise { const client = initReadOnlyOpenbookClient(); diff --git a/ts/client/src/test/openOrders.ts b/ts/client/src/test/openOrders.ts index 42db867de..a7cb9cc34 100644 --- a/ts/client/src/test/openOrders.ts +++ b/ts/client/src/test/openOrders.ts @@ -1,12 +1,7 @@ import { PublicKey } from '@solana/web3.js'; -import { - Market, - OpenOrders, - SideUtils, - initOpenbookClient, - initReadOnlyOpenbookClient, -} from '..'; +import { Market, OpenOrders, SideUtils } from '..'; import { OpenOrdersIndexer } from '../accounts/openOrdersIndexer'; +import { initOpenbookClient, initReadOnlyOpenbookClient } from './util'; async function testLoadIndexerNonExistent(): Promise { const client = initReadOnlyOpenbookClient(); diff --git a/ts/client/src/test/util.ts b/ts/client/src/test/util.ts new file mode 100644 index 000000000..9407dd84a --- /dev/null +++ b/ts/client/src/test/util.ts @@ -0,0 +1,21 @@ +import { Connection, Keypair } from '@solana/web3.js'; +import { OpenBookV2Client } from '..'; +import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; + +export function initReadOnlyOpenbookClient(): OpenBookV2Client { + const conn = new Connection(process.env.SOL_RPC_URL!); + const stubWallet = new Wallet(Keypair.generate()); + const provider = new AnchorProvider(conn, stubWallet, {}); + return new OpenBookV2Client(provider); +} + +export function initOpenbookClient(): OpenBookV2Client { + const conn = new Connection(process.env.SOL_RPC_URL!, 'processed'); + const wallet = new Wallet( + Keypair.fromSecretKey(Uint8Array.from(JSON.parse(process.env.KEYPAIR!))), + ); + const provider = new AnchorProvider(conn, wallet, {}); + return new OpenBookV2Client(provider, undefined, { + prioritizationFee: 10_000, + }); +} diff --git a/ts/client/src/utils/utils.ts b/ts/client/src/utils/utils.ts index c9e4fc77e..d6752d78e 100644 --- a/ts/client/src/utils/utils.ts +++ b/ts/client/src/utils/utils.ts @@ -1,6 +1,4 @@ import { - Connection, - Keypair, PublicKey, SystemProgram, TransactionInstruction, @@ -10,8 +8,6 @@ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, } from '@solana/spl-token'; -import { OpenBookV2Client } from '..'; -import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; export const SideUtils = { Bid: { bid: {} }, @@ -115,24 +111,6 @@ export async function createAssociatedTokenAccountIdempotentInstruction( }); } -export function initReadOnlyOpenbookClient(): OpenBookV2Client { - const conn = new Connection(process.env.SOL_RPC_URL!); - const stubWallet = new Wallet(Keypair.generate()); - const provider = new AnchorProvider(conn, stubWallet, {}); - return new OpenBookV2Client(provider); -} - -export function initOpenbookClient(): OpenBookV2Client { - const conn = new Connection(process.env.SOL_RPC_URL!, 'processed'); - const wallet = new Wallet( - Keypair.fromSecretKey(Uint8Array.from(JSON.parse(process.env.KEYPAIR!))), - ); - const provider = new AnchorProvider(conn, wallet, {}); - return new OpenBookV2Client(provider, undefined, { - prioritizationFee: 10_000, - }); -} - export function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); }