@heyamiko/amiko-cli 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +26 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19158,6 +19158,22 @@ async function mppCreditsTopup(params) {
19158
19158
  }
19159
19159
  }
19160
19160
 
19161
+ // src/lib/price.ts
19162
+ var DEFAULT_PLATFORM_URL2 = "https://platform.heyamiko.com";
19163
+ async function getTokenUsdPrice(auth, symbolOrMint) {
19164
+ const base = (auth.platformUrl || DEFAULT_PLATFORM_URL2).replace(/\/$/, "");
19165
+ const param = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(symbolOrMint) ? `mint=${encodeURIComponent(symbolOrMint)}` : `symbol=${encodeURIComponent(symbolOrMint)}`;
19166
+ try {
19167
+ const res = await fetch(`${base}/api/prices/token?${param}`);
19168
+ if (!res.ok)
19169
+ return null;
19170
+ const data = await res.json();
19171
+ return typeof data.price === "number" ? data.price : null;
19172
+ } catch {
19173
+ return null;
19174
+ }
19175
+ }
19176
+
19161
19177
  // src/commands/credits.ts
19162
19178
  function promptYesNo2(question) {
19163
19179
  if (!process.stdin.isTTY)
@@ -19242,34 +19258,19 @@ function registerCreditsCommand(program2) {
19242
19258
  pricePerToken = 1;
19243
19259
  } else {
19244
19260
  const spinner2 = ora(`Fetching ${token} price...`).start();
19245
- try {
19246
- const MINTS = {
19247
- AMIKO: "AY1Ww6MxwC3cCiyrandHqLrp4FXvzgcwQTZpJ2FEpump",
19248
- SOL: "So11111111111111111111111111111111111111112"
19249
- };
19250
- const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
19251
- const mint = MINTS[token.toUpperCase()];
19252
- if (!mint) {
19253
- spinner2.stop();
19254
- console.error(error(`Unknown token: ${token}`));
19255
- process.exit(1);
19256
- }
19257
- const decimals = token.toUpperCase() === "SOL" ? 9 : 6;
19258
- const oneToken = Math.pow(10, decimals).toString();
19259
- const jupRes = await fetch(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${mint}&outputMint=${USDC_MINT}&amount=${oneToken}&slippageBps=100`);
19260
- if (!jupRes.ok) {
19261
- spinner2.stop();
19262
- console.error(error("Failed to fetch token price"));
19263
- process.exit(1);
19264
- }
19265
- const jupData = await jupRes.json();
19266
- pricePerToken = parseFloat(jupData.outAmount) / 1e6;
19267
- spinner2.stop();
19268
- } catch {
19261
+ const supported = ["AMIKO", "SOL"];
19262
+ if (!supported.includes(token.toUpperCase())) {
19269
19263
  spinner2.stop();
19264
+ console.error(error(`Unknown token: ${token}`));
19265
+ process.exit(1);
19266
+ }
19267
+ const price = await getTokenUsdPrice(auth, token.toUpperCase());
19268
+ spinner2.stop();
19269
+ if (price == null || price <= 0) {
19270
19270
  console.error(error("Failed to fetch token price"));
19271
19271
  process.exit(1);
19272
19272
  }
19273
+ pricePerToken = price;
19273
19274
  }
19274
19275
  let creditsAmount;
19275
19276
  let usdAmount;
@@ -20160,15 +20161,6 @@ function registerAmazonCommand(program2) {
20160
20161
 
20161
20162
  // src/commands/services.ts
20162
20163
  var TREASURY4 = "FPiZAf3jEnNfCwfvbv46jdPfHbmSepD4Q6iHiLJDQXvb";
20163
- var AMIKO_MINT = "AY1Ww6MxwC3cCiyrandHqLrp4FXvzgcwQTZpJ2FEpump";
20164
- var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
20165
- async function getAmikoPrice() {
20166
- const res = await fetch(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${AMIKO_MINT}&outputMint=${USDC_MINT}&amount=${1e6}&slippageBps=100`);
20167
- if (!res.ok)
20168
- return 0;
20169
- const data = await res.json();
20170
- return parseFloat(data.outAmount) / 1e6;
20171
- }
20172
20164
  function usdToAmiko(usd2, pricePerAmiko) {
20173
20165
  if (pricePerAmiko <= 0)
20174
20166
  return "1";
@@ -20187,7 +20179,7 @@ async function payAndCall(mppBase2, method, path2, auth, wallet, amountOrAuto, b
20187
20179
  const methodSpec = pathSpec?.[method.toLowerCase()];
20188
20180
  const usdPrice = parseFloat(methodSpec?.["x-payment-info"]?.price || "0");
20189
20181
  if (usdPrice > 0) {
20190
- const amikoPrice = await getAmikoPrice();
20182
+ const amikoPrice = await getTokenUsdPrice(auth, "AMIKO") ?? 0;
20191
20183
  amount2 = usdToAmiko(usdPrice, amikoPrice);
20192
20184
  onProgress?.(`Price: $${usdPrice.toFixed(4)} = ${amount2} AMIKO`);
20193
20185
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyamiko/amiko-cli",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Amiko CLI — swap tokens, manage credits, bridge cross-chain, and call marketplace agents",
5
5
  "type": "module",
6
6
  "bin": {