Skip to content

Commit efead37

Browse files
committed
refactor: streamline Raydium positions handling and update module exports
1 parent 2236677 commit efead37

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

projects/helper/solana.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { queryAllium } = require('./allium');
1010

1111
const sdk = require('@defillama/sdk');
1212
const { endpointMap, endpoint } = require('./svmChainConfig.js')
13+
const { addRaydiumPositions } = require('../krystal/solana.js')
1314

1415
/** Address of the SPL Token program */
1516
const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')
@@ -743,4 +744,5 @@ module.exports = {
743744
i80f48ToNumber,
744745
runInChunks,
745746
getTokenAccountBalances,
747+
addRaydiumPositions,
746748
};

projects/krystal/solana.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { Program } = require("@coral-xyz/anchor");
21
const { PublicKey } = require("@solana/web3.js");
32
const {
43
getConnection,
@@ -17,18 +16,25 @@ const CLMM_PROGRAM_ID = new PublicKey(
1716
const POSITION_SEED = Buffer.from("position", "utf8");
1817

1918
async 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

Comments
 (0)