forked from 0xfnzero/sol-trade-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_infrastructure.ts
More file actions
53 lines (44 loc) · 1.75 KB
/
shared_infrastructure.ts
File metadata and controls
53 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Shared Infrastructure Example
*
* This example demonstrates how to share infrastructure across multiple wallets.
* The infrastructure (RPC client, SWQOS clients) is created once and shared.
*/
import {
InfrastructureConfig,
TradingInfrastructure,
TradingClient,
SwqosConfig,
SwqosType,
SwqosRegion,
} from 'sol-trade-sdk';
import { Keypair } from '@solana/web3.js';
async function main() {
const rpcUrl = process.env.RPC_URL || 'https://api.mainnet-beta.solana.com';
// Configure SWQoS services
const swqosConfigs: SwqosConfig[] = [
{ type: SwqosType.DEFAULT, url: rpcUrl },
{ type: SwqosType.JITO, uuid: 'your_uuid', region: SwqosRegion.FRANKFURT },
{ type: SwqosType.BLOXROUTE, apiToken: 'your_api_token', region: SwqosRegion.FRANKFURT },
];
// Create infrastructure once (expensive operation)
const infraConfig = new InfrastructureConfig({
rpcUrl,
swqosConfigs,
});
const infrastructure = await TradingInfrastructure.new(infraConfig);
console.log('Infrastructure created successfully!');
// Create multiple clients sharing the same infrastructure (fast)
const payer1 = Keypair.generate();
const payer2 = Keypair.generate();
const payer3 = Keypair.generate();
const client1 = TradingClient.fromInfrastructure(payer1, infrastructure, true);
const client2 = TradingClient.fromInfrastructure(payer2, infrastructure, true);
const client3 = TradingClient.fromInfrastructure(payer3, infrastructure, true);
console.log(`Client 1: ${client1.payerPubkey}`);
console.log(`Client 2: ${client2.payerPubkey}`);
console.log(`Client 3: ${client3.payerPubkey}`);
// All clients share the same RPC and SWQoS connections
console.log('All clients share the same infrastructure!');
}
main().catch(console.error);