Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eac2a4d
chore: update oxlint config to ts
ChiefWoods Aug 30, 2026
0c8d81c
chore: replace prettier with oxfmt
ChiefWoods Aug 30, 2026
9626459
feat: add jupiter-api-ts
ChiefWoods Aug 30, 2026
3354c41
feat: add rpcUrl field in config
ChiefWoods Aug 30, 2026
1a13d9f
feat: add SolanaRpc lib
ChiefWoods Aug 30, 2026
1d3eb40
feat: add dry-run flag
ChiefWoods Aug 30, 2026
e38c138
feat: add JupiterApi lib
ChiefWoods Aug 30, 2026
995c432
refactor: replace asset helpers using JupiterDatapi
ChiefWoods Aug 30, 2026
66594a2
feat: add @solana-program/token-2022
ChiefWoods Aug 30, 2026
2393822
feat: add getScaledUiMultiplier method to SolanaRpc
ChiefWoods Aug 30, 2026
b8f7b1a
feat: add getTokenProgram method to SolanaRpc
ChiefWoods Aug 30, 2026
d89bc77
refactor: use Datapi client and SolanaRpc
ChiefWoods Aug 30, 2026
a1215a8
docs: update readme
ChiefWoods Aug 30, 2026
21f7899
refactor: replace handrolled clients with API-backed clients
ChiefWoods Aug 30, 2026
622fd7c
chore: use unambiguous fallback methods
ChiefWoods Aug 31, 2026
afc8dc4
feat: add SolanaTransactions lib
ChiefWoods Aug 31, 2026
15f2c89
chore: update signTransaction method to accept Base64EncodedWireTrans…
ChiefWoods Aug 31, 2026
178b55b
feat: add getTokenPrograms and getTokenAccountsByOwner methods
ChiefWoods Aug 31, 2026
008e494
docs: update readme on dry-run
ChiefWoods Aug 31, 2026
9a2ca84
refactor: replace UltraClient and use primitives for transfer and rec…
ChiefWoods Aug 31, 2026
89b3f84
chore: remove old clients
ChiefWoods Aug 31, 2026
f3522cd
refactor: use RPC primitive and remove request builder
ChiefWoods Aug 31, 2026
30339e4
feat: lift portfolio, transfer and reclaim to top level, update spot …
ChiefWoods Aug 31, 2026
833d2dc
refactor: replace Datapi searchAssets with getTokensV2Search
ChiefWoods Aug 31, 2026
ddaa585
refactor: replace parallel API calls with single call
ChiefWoods Aug 31, 2026
37473aa
feat: add support for negative chain amount
ChiefWoods Aug 31, 2026
c8d648e
chore: fallback to config active key if address is not passed for len…
ChiefWoods Aug 31, 2026
be7312d
feat: add lend borrow commands
ChiefWoods Aug 31, 2026
60fc9df
feat: add dca commands
ChiefWoods Aug 31, 2026
44b63aa
feat: add signTransactionWith method
ChiefWoods Aug 31, 2026
28b659b
feat: add invite commands
ChiefWoods Aug 31, 2026
70f0d02
feat: add jlp commands
ChiefWoods Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: replace asset helpers using JupiterDatapi
  • Loading branch information
ChiefWoods committed Aug 30, 2026
commit 995c432df21358f505088f3db88f53debe120576
64 changes: 60 additions & 4 deletions src/lib/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { address, isAddress } from "@solana/kit";
import type { JupiterDatapi, JupiterDatapiTypes } from "jupiter-api-ts";

import { DatapiClient, type Token } from "../clients/DatapiClient.ts";
import { UltraClient } from "../clients/UltraClient.ts";

type AssetInfo = {
Expand Down Expand Up @@ -29,6 +29,61 @@ export const Asset = {

export type Asset = (typeof Asset)[keyof typeof Asset];

export type Token = JupiterDatapiTypes.Asset & { decimals: number };

export async function searchTokens(params: {
datapi: JupiterDatapi;
query: string;
limit?: number;
}): Promise<Token[]> {
const { datapi, ...query } = params;
const response = await datapi.searchAssets({ query });
if (response.error || !response.data) {
throw new Error("Data API token search failed.");
}
return response.data.filter(
(asset): asset is Token => typeof asset.decimals === "number"
);
}

export async function getTokensByMints(
datapi: JupiterDatapi,
mints: string[]
): Promise<Token[]> {
if (mints.length === 0) {
return [];
}
const batches: string[][] = [];
for (let i = 0; i < mints.length; i += 100) {
batches.push(mints.slice(i, i + 100));
}
const results = await Promise.all(
batches.map(async (batch) => {
const response = await datapi.getAssetsByIds({
query: { ids: batch.join(",") },
});
if (response.error || !response.data) {
throw new Error("Data API asset lookup failed.");
}
return response.data.assets.filter(
(asset): asset is Token => typeof asset.decimals === "number"
);
})
);
return results.flat();
}

export async function resolveToken(
datapi: JupiterDatapi,
input: string
): Promise<Token> {
const [token] = await searchTokens({ datapi, query: input, limit: 1 });
if (!token) {
throw new Error(`Token not found: ${input}`);
}
return token;
}

export function resolveAsset(name: string): (typeof Asset)[keyof typeof Asset] {
const key = name.toUpperCase();
const asset = Asset[key as keyof typeof Asset];
Expand All @@ -39,25 +94,26 @@ export function resolveAsset(name: string): (typeof Asset)[keyof typeof Asset] {
}

export async function resolveWalletAsset(
datapi: JupiterDatapi,
walletAddress: string,
asset: string
): Promise<Token> {
if (isAddress(asset)) {
return DatapiClient.resolveToken(asset);
return resolveToken(datapi, asset);
}

const key = asset.toUpperCase();
// Prevent full holdings lookup for well-known tokens
if (key in Asset) {
return DatapiClient.resolveToken(Asset[key as keyof typeof Asset].id);
return resolveToken(datapi, Asset[key as keyof typeof Asset].id);
}

const holdings = await UltraClient.getHoldings(walletAddress);
const mints = Object.keys(holdings.tokens);
if (BigInt(holdings.amount) > 0n && !mints.includes(Asset.SOL.id)) {
mints.push(Asset.SOL.id);
}
const tokens = await DatapiClient.getTokensByMints(mints);
const tokens = await getTokensByMints(datapi, mints);
const query = asset.toLowerCase();
const matches = tokens.filter((t) => t.symbol.toLowerCase() === query);

Expand Down