-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtrimMainnet.ts
58 lines (49 loc) · 1.7 KB
/
trimMainnet.ts
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
54
55
56
57
58
import fs from 'fs';
import { swapConfig } from './swapConfig';
interface PoolInfo {
id: string;
baseMint: string;
quoteMint: string;
lpMint: string;
version: number;
programId: string;
authority: string;
openOrders: string;
targetOrders: string;
baseVault: string;
quoteVault: string;
withdrawQueue: string;
lpVault: string;
marketVersion: number;
marketProgramId: string;
marketId: string;
marketAuthority: string;
marketBaseVault: string;
marketQuoteVault: string;
marketBids: string;
marketAsks: string;
marketEventQueue: string;
}
function trimMainnetJson() {
// Read the local mainnet.json file
const mainnetData = JSON.parse(fs.readFileSync('../mainnet.json', 'utf-8'));
// Get the token addresses from swapConfig
const { tokenAAddress, tokenBAddress } = swapConfig;
// Find the pool that matches the token pair in both official and unofficial pools
const relevantPool = [...mainnetData.official, ...(mainnetData.unOfficial || [])].find((pool: PoolInfo) =>
(pool.baseMint === tokenAAddress && pool.quoteMint === tokenBAddress) ||
(pool.baseMint === tokenBAddress && pool.quoteMint === tokenAAddress)
);
if (!relevantPool) {
console.error('No matching pool found for the given token pair');
return;
}
// Create a new object with only the necessary information
const trimmedData = {
official: [relevantPool]
};
// Write the trimmed data to a new file
fs.writeFileSync('trimmed_mainnet.json', JSON.stringify(trimmedData, null, 2));
console.log('Trimmed mainnet.json file has been created as trimmed_mainnet.json');
}
trimMainnetJson();