Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ app.get("/health", (c) => c.json({ ok: true, service: "api" }));
// Swap proxy (CORS workaround for web UI)
app.get("/v1/swaps/:id", async (c) => {
const id = c.req.param("id");
const upstream = await fetch(`https://apilendaswap.lendasat.com/swap/${encodeURIComponent(id)}`);
const upstream = await fetch(`https://api.lendaswap.com/swap/${encodeURIComponent(id)}`);
if (!upstream.ok) {
const text = await upstream.text();
throw new HTTPException(upstream.status === 400 ? 404 : (upstream.status as any), {
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@arkade-os/boltz-swap": "^0.3.8",
"@arkade-os/sdk": "^0.4.10",
"@lendasat/lendaswap-sdk-pure": "^0.0.2",
"@lendasat/lendaswap-sdk-pure": "^0.2.25",
"@noble/hashes": "^2.0.1",
"@scure/base": "^2.0.0",
"@scure/btc-signer": "^2.0.1",
Expand Down
10 changes: 6 additions & 4 deletions cli/src/commands/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
toStablecoinToken,
resolveCurrency,
parseBtcAmount,
parseStablecoinAmount,
} from "../utils/token.js";
import type { CashConfig } from "../config.js";
import type { ParsedArgs } from "minimist";
Expand Down Expand Up @@ -37,7 +38,7 @@ export async function handleReceive(
if (resolved !== "btc" && !where) {
if (!amountStr) {
return outputError(
`Missing --amount <${currency}> (e.g. --amount 10 for 10 ${currency.toUpperCase()})`
`Missing --amount <${currency}> (e.g. --amount 1.02 for $1.02 ${currency.toUpperCase()})`
);
}
const amount = parseFloat(amountStr);
Expand Down Expand Up @@ -78,7 +79,7 @@ export async function handleReceive(
return outputError(
resolved === "btc"
? `Missing --amount (${currency === "sats" ? "sats" : "BTC"} required for lightning invoices)`
: `Missing --amount <${resolved}> (e.g. --amount 10 for 10 ${resolved.toUpperCase()})`
: `Missing --amount <${resolved}> (e.g. --amount 1.02 for $1.02 ${resolved.toUpperCase()})`
);
}

Expand All @@ -90,8 +91,9 @@ export async function handleReceive(
if (sats === null) return outputError(`Invalid amount: ${amountStr}`);
amount = sats;
} else {
amount = parseFloat(amountStr);
if (isNaN(amount) || amount <= 0) return outputError(`Invalid amount: ${amountStr}`);
const units = parseStablecoinAmount(amountStr, resolved, where);
if (units === null) return outputError(`Invalid amount: ${amountStr}`);
amount = units;
}
}

Expand Down
6 changes: 4 additions & 2 deletions cli/src/commands/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
toEvmChain,
resolveCurrency,
parseBtcAmount,
parseStablecoinAmount,
} from "../utils/token.js";
import type { ParsedArgs } from "minimist";

Expand Down Expand Up @@ -96,8 +97,9 @@ export async function handleSend(
if (sats === null) return outputError(`Invalid amount: ${amountStr}`);
amount = sats;
} else {
amount = parseFloat(amountStr);
if (isNaN(amount) || amount <= 0) return outputError(`Invalid amount: ${amountStr}`);
const units = parseStablecoinAmount(amountStr, resolved, where);
if (units === null) return outputError(`Invalid amount: ${amountStr}`);
amount = units;
}

if (!isValidWhere(where)) {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { outputSuccess, outputError } from "../output.js";
import { getDaemonUrl, daemonGet } from "../daemonClient.js";
import type { ParsedArgs } from "minimist";

const LENDASWAP_API = "https://apilendaswap.lendasat.com";
const LENDASWAP_API = "https://api.lendaswap.com";

export async function handleSwap(ctx: CashContext, args: ParsedArgs): Promise<never> {
const swapId = (args._[1] as string) || (args.id as string);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { AuthMonitor } from "./authMonitor.js";
import type { WebhookRegistry, SwapEventType } from "./notifier.js";
import type { EvmChain, StablecoinToken, StablecoinSwapInfo, StablecoinSwapStatus } from "@clw-cash/skills";

const LENDASWAP_API = "https://apilendaswap.lendasat.com";
const LENDASWAP_API = "https://api.lendaswap.com";

async function fetchRemoteSwap(swapId: string): Promise<Record<string, unknown> | null> {
try {
Expand Down
13 changes: 12 additions & 1 deletion cli/src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StablecoinToken, EvmChain } from "@clw-cash/skills";
import { toSmallestUnit, type StablecoinToken, type EvmChain } from "@clw-cash/skills";

const TOKEN_MAP: Record<string, Record<string, StablecoinToken>> = {
usdt: { polygon: "usdt0_pol", ethereum: "usdt_eth", arbitrum: "usdt_arb" },
Expand Down Expand Up @@ -66,3 +66,14 @@ export function toStablecoinToken(currency: string, chain: string): StablecoinTo
export function toEvmChain(where: string): EvmChain {
return where as EvmChain;
}

/**
* Parse a human-readable stablecoin amount (e.g. "1.02" for $1.02)
* and return the value in smallest token units (e.g. 1020000 for USDC).
*/
export function parseStablecoinAmount(amountStr: string, currency: string, where: string): number | null {
const value = parseFloat(amountStr);
if (isNaN(value) || value <= 0) return null;
const token = toStablecoinToken(currency, where);
return toSmallestUnit(value, token);
}
Loading
Loading