Skip to content

Commit

Permalink
fix pricing fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Geninsus committed Nov 5, 2024
1 parent e42239c commit 3aca075
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
38 changes: 27 additions & 11 deletions packages/plugins/src/plugins/jupiter/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,35 @@ export function getVotePda(owner: string): PublicKey {
)[0];
}

const maxIdsPerRequest = 100;

export async function getJupiterPrices(mints: PublicKey[], vsMint: PublicKey) {
const res = await axios.get<unknown, AxiosResponse<PriceResponse>>(
'https://price.jup.ag/v4/price',
{
params: {
ids: mints.map((m) => m.toString()).join(','),
vsToken: vsMint.toString(),
},
}
);
let res;
const pricesData = [];
let subMints;
let start = 0;
let end = maxIdsPerRequest - 1;
do {
subMints = mints.slice(start, end);
res = await axios.get<unknown, AxiosResponse<PriceResponse>>(
'https://api.jup.ag/price/v2',
{
params: {
ids: subMints.map((m) => m.toString()).join(','),
vsToken: vsMint.toString(),
},
}
);
start += maxIdsPerRequest;
end += maxIdsPerRequest;
pricesData.push(res.data.data);
} while (mints.at(start));

const prices: Map<string, number> = new Map();
for (const [, value] of Object.entries(res.data.data)) {
prices.set(value.id, value.price);
for (const priceData of pricesData) {
for (const [, value] of Object.entries(priceData)) {
prices.set(value.id, value.price);
}
}
return prices;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/src/plugins/jupiter/pricingJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { lstsKey, platformId as sanctumPlatformId } from '../sanctum/constants';

const mints = [
'xLfNTYy76B8Tiix3hA51Jyvc1kMSFV4sPdR7szTZsRu', // xLifinity
'BANXbTpN8U2cU41FjPxe2Ti37PiT5cCxLUKDQZuJeMMR', // Banx
'4LLbsb5ReP3yEtYzmXewyGjcir5uXtKFURtaEUVC2AHs', // Parcl
'SHARKSYJjqaNyxVfrpnBN9pjgkhwDhatnMyicWPnr1s', // Shark
'KMNo3nJsBXfcpJTVhZcXLW7RmTwTt4GVFE7suUBo9sS', // Kamino
'DdFPRnccQqLD4zCHrBqdY95D6hvw6PLWp9DEXj1fLCL9', // Wrapped USDC (Allbridge from Ethereum)
'eqKJTf1Do4MDPyKisMYqVaUFpkEFAs3riGF3ceDH2Ca', // Wrapped USDC (Allbridge from Polygon)
'8Yv9Jz4z7BUHP68dz8E8m3tMe6NKgpMUKn8KVqrPA6Fr', // Wrapped USDC (Allbridge from Avalanche)
Expand Down

0 comments on commit 3aca075

Please sign in to comment.