1- const { Program } = require ( "@coral-xyz/anchor" ) ;
21const { PublicKey } = require ( "@solana/web3.js" ) ;
32const {
43 getConnection,
@@ -17,18 +16,25 @@ const CLMM_PROGRAM_ID = new PublicKey(
1716const POSITION_SEED = Buffer . from ( "position" , "utf8" ) ;
1817
1918async function tvl ( api ) {
19+
20+ // Load all the vaults in the program
21+ const vaults = await program . account . userVault . all ( ) ;
22+ await addRaydiumPositions ( { api, owners : vaults . map ( i => i . publicKey ) } )
23+
24+ }
25+
26+ async function addRaydiumPositions ( { api, owners = [ ] , owner } ) {
2027 const connection = getConnection ( ) ;
2128
22- const program = new Program ( idl , { connection } ) ;
2329 const pools = new Map ( ) ;
30+
2431 const pdaPersonalPositionAddressesAll = [ ]
32+ if ( owner ) owners . push ( owner )
2533
26- // Load all the vaults in the program
27- const vaults = await program . account . userVault . all ( ) ;
2834
2935 const positions = [ ] ;
30- for ( const account of vaults ) {
31- const vault = account . publicKey ;
36+ for ( let vault of owners ) {
37+ if ( typeof vault === "string" ) vault = new PublicKey ( vault ) ;
3238 await findClmmPositionsByOwner ( connection , vault ) ;
3339 }
3440
@@ -99,6 +105,7 @@ async function tvl(api) {
99105 const pdaPersonalPositionAddresses = tokenNftMints . map ( getPdaPersonalPositionAddress )
100106 pdaPersonalPositionAddressesAll . push ( ...pdaPersonalPositionAddresses )
101107 }
108+
102109}
103110
104111
@@ -116,4 +123,4 @@ async function tvlApi(api) {
116123 api . addUSDValue ( + res . tvl )
117124}
118125
119- module . exports = { tvl : tvlApi } ;
126+ module . exports = { tvl : tvlApi , addRaydiumPositions , } ;
0 commit comments