Get Position of a User Wallet
Fetch and query positions and LB Pair details for a particular user
async function getAllLbPairPositionForOwner(ownerAddress) {
const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
//get all Position and LB Pair address for a particular owner (wallet address)
const operationsDoc = `
query MyQuery {
meteora_dlmm_PositionV2(
where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
) {
upperBinId
lowerBinId
totalClaimedFeeYAmount
totalClaimedFeeXAmount
lbPair
owner
}
meteora_dlmm_Position(
where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
) {
lbPair
lowerBinId
upperBinId
totalClaimedFeeYAmount
totalClaimedFeeXAmount
owner
}
}
`; //you can cherrypick the fields as per your requirement
const result = await fetch(
`https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
{
method: "POST",
body: JSON.stringify({
query: operationsDoc,
variables: {},
operationName: "MyQuery",
}),
}
);
const { errors, data } = await result.json();
if (data.meteora_dlmm_Position.length > 0) {
for (let index = 0; index < data.meteora_dlmm_Position.length; index++) {
const position = data.meteora_dlmm_Position[index];
//get all Lb pair details for the position
const LbPairDetails = await fetch(
`https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
{
method: "POST",
body: JSON.stringify({
query: `
query MyQuery {
meteora_dlmm_LbPair(where: {pubkey: {_eq: ${JSON.stringify(position.lbPair)}}}
) {
pubkey
oracle
pairType
reserveX
reserveY
status
tokenXMint
tokenYMint
}
}
`, //querying the LB pair details
variables: {},
operationName: "MyQuery",
}),
}
);
const LBPairResponse = await LbPairDetails.json();
console.log({
owner: position.owner,
lbPair: position.lbPair,
lowerBindId: position.lowerBinId,
upperBinId: position.upperBinId,
lbPairDetails: LBPairResponse.data.meteora_dlmm_LbPair[0],
});
//adding a delay of 2 seconds to avoid rate limiting, only for free API Keys.
await new Promise((resolve) => setTimeout(resolve, 2000));
}
}
if (data.meteora_dlmm_PositionV2.length > 0) {
for (let index = 0; index < data.meteora_dlmm_PositionV2.length; index++) {
const position = data.meteora_dlmm_PositionV2[index];
//get all Lb pair details for the positionV2
const LbPairDetails = await fetch(
`https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
{
method: "POST",
body: JSON.stringify({
query: `
query MyQuery {
meteora_dlmm_LbPair(
where: {pubkey: {_eq: ${JSON.stringify(position.lbPair)}}}
) {
pubkey
oracle
pairType
reserveX
reserveY
status
tokenXMint
tokenYMint
}
}
`, //querying the LB pair details
variables: {},
operationName: "MyQuery",
}),
}
);
const LBPairResponse = await LbPairDetails.json();
console.log({
owner: position.owner,
lbPair: position.lbPair,
lowerBindId: position.lowerBinId,
upperBinId: position.upperBinId,
lbPairDetails: LBPairResponse.data.meteora_dlmm_LbPair[0],
});
//adding a delay of 2 seconds to avoid rate limiting, only for free API Keys.
//await new Promise((resolve) => setTimeout(resolve, 2000));
}
}
}
getAllLbPairPositionForOwner("2rJeSN4HJTvkG5VqwHxYeLHo6up9WBScPKgJ2kQbiSr4")
//owner address for which we are fetching the positionsLast updated