Skip to content
Draft
Show file tree
Hide file tree
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
feat: add support for negative chain amount
  • Loading branch information
ChiefWoods committed Aug 31, 2026
commit 37473aa295f009ca5de11e61459135f49377a5a4
12 changes: 12 additions & 0 deletions src/lib/NumberConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ describe("fromChainAmount", () => {
expect(NumberConverter.fromChainAmount("1000000", 6, 0.5)).toBe("0.5");
});

test("signed amounts", () => {
expect(NumberConverter.fromChainAmount("-1500000", 6)).toBe("-1.5");
expect(NumberConverter.fromChainAmount("-30000000", 9)).toBe("-0.03");
expect(NumberConverter.fromChainAmount("-0", 6)).toBe("0");
});

test("multiplier of 1 is no-op", () => {
expect(NumberConverter.fromChainAmount("1500000", 6, 1)).toBe("1.5");
});
Expand Down Expand Up @@ -124,6 +130,12 @@ describe("toChainAmount", () => {
expect(NumberConverter.toChainAmount("1.5", 6, 1)).toBe("1500000");
});

test("signed amounts", () => {
expect(NumberConverter.toChainAmount("-1.5", 6)).toBe("-1500000");
expect(NumberConverter.toChainAmount("-0.03", 9)).toBe("-30000000");
expect(NumberConverter.toChainAmount("-0", 6)).toBe("0");
});

test("round-trip with fromChainAmount", () => {
const decimals = 6;
const cases = ["1000000", "1500000", "500000", "100000000", "1"];
Expand Down
16 changes: 16 additions & 0 deletions src/lib/NumberConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class NumberConverter {
multiplier?: number | undefined
): string {
const amountString = amount.toString();
if (amountString.startsWith("-")) {
const converted = this.fromChainAmount(
amountString.slice(1),
decimals,
multiplier
);
return converted === "0" ? "0" : `-${converted}`;
}

let postDecimals: string;
if (amountString.length <= decimals) {
Expand Down Expand Up @@ -67,6 +75,14 @@ export class NumberConverter {
decimals: number,
multiplier?: number | undefined
): string {
if (amount.startsWith("-")) {
const converted = this.toChainAmount(
amount.slice(1),
decimals,
multiplier
);
return converted === "0" ? "0" : `-${converted}`;
}
const [integerPart, fractionalPart] = amount.split(".");
const postDecimals = this.removeInsignificantZeros(
(integerPart ?? "") +
Expand Down