@heyamiko/amiko-cli 0.6.0 → 0.6.1
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.
- package/dist/index.js +55 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75931,7 +75931,47 @@ function registerSearchCommand(program2) {
|
|
|
75931
75931
|
|
|
75932
75932
|
// src/commands/services.ts
|
|
75933
75933
|
var TREASURY2 = "FPiZAf3jEnNfCwfvbv46jdPfHbmSepD4Q6iHiLJDQXvb";
|
|
75934
|
-
|
|
75934
|
+
var AMIKO_MINT = "AY1Ww6MxwC3cCiyrandHqLrp4FXvzgcwQTZpJ2FEpump";
|
|
75935
|
+
var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
75936
|
+
async function getAmikoPrice() {
|
|
75937
|
+
const res = await fetch(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${AMIKO_MINT}&outputMint=${USDC_MINT}&amount=${1e6}&slippageBps=100`);
|
|
75938
|
+
if (!res.ok)
|
|
75939
|
+
return 0;
|
|
75940
|
+
const data = await res.json();
|
|
75941
|
+
return parseFloat(data.outAmount) / 1e6;
|
|
75942
|
+
}
|
|
75943
|
+
function usdToAmiko(usd2, pricePerAmiko) {
|
|
75944
|
+
if (pricePerAmiko <= 0)
|
|
75945
|
+
return "1";
|
|
75946
|
+
const amount2 = usd2 / pricePerAmiko;
|
|
75947
|
+
return Math.ceil(amount2 * 100) / 100 + "";
|
|
75948
|
+
}
|
|
75949
|
+
async function payAndCall(mppBase2, method, path, billingBase2, billingToken, solanaWallet, amountOrAuto, body, onProgress, token = "AMIKO") {
|
|
75950
|
+
let amount2 = amountOrAuto;
|
|
75951
|
+
if (amount2 === "auto") {
|
|
75952
|
+
onProgress?.("Fetching price...");
|
|
75953
|
+
try {
|
|
75954
|
+
const specRes = await fetch(`${mppBase2}/openapi.json`);
|
|
75955
|
+
if (specRes.ok) {
|
|
75956
|
+
const spec = await specRes.json();
|
|
75957
|
+
const pathSpec = spec.paths?.[path];
|
|
75958
|
+
const methodSpec = pathSpec?.[method.toLowerCase()];
|
|
75959
|
+
const usdPrice = parseFloat(methodSpec?.["x-payment-info"]?.price || "0");
|
|
75960
|
+
if (usdPrice > 0) {
|
|
75961
|
+
const amikoPrice = await getAmikoPrice();
|
|
75962
|
+
amount2 = usdToAmiko(usdPrice, amikoPrice);
|
|
75963
|
+
onProgress?.(`Price: $${usdPrice.toFixed(4)} = ${amount2} AMIKO`);
|
|
75964
|
+
} else {
|
|
75965
|
+
amount2 = "1";
|
|
75966
|
+
}
|
|
75967
|
+
} else {
|
|
75968
|
+
amount2 = "1";
|
|
75969
|
+
}
|
|
75970
|
+
} catch {
|
|
75971
|
+
amount2 = "1";
|
|
75972
|
+
}
|
|
75973
|
+
}
|
|
75974
|
+
onProgress?.(`Paying ${amount2} AMIKO...`);
|
|
75935
75975
|
const transferRes = await fetch(`${billingBase2}/api/crossmint/wallets/${encodeURIComponent(solanaWallet)}/transfer`, {
|
|
75936
75976
|
method: "POST",
|
|
75937
75977
|
headers: {
|
|
@@ -75940,8 +75980,8 @@ async function payAndCall(mppBase2, method, path, billingBase2, billingToken, so
|
|
|
75940
75980
|
},
|
|
75941
75981
|
body: JSON.stringify({
|
|
75942
75982
|
to: TREASURY2,
|
|
75943
|
-
amount:
|
|
75944
|
-
token
|
|
75983
|
+
amount: amount2,
|
|
75984
|
+
token,
|
|
75945
75985
|
chain: "solana"
|
|
75946
75986
|
})
|
|
75947
75987
|
});
|
|
@@ -75963,7 +76003,7 @@ async function payAndCall(mppBase2, method, path, billingBase2, billingToken, so
|
|
|
75963
76003
|
}
|
|
75964
76004
|
const url2 = path.startsWith("http") ? path : `${mppBase2}${path}`;
|
|
75965
76005
|
const res = await fetch(url2, fetchOpts);
|
|
75966
|
-
return { res, txHash };
|
|
76006
|
+
return { res, txHash, amikoSpent: amount2 };
|
|
75967
76007
|
}
|
|
75968
76008
|
function registerServicesCommand(program2) {
|
|
75969
76009
|
const svc = program2.command("service").alias("svc").description("Call any MPP service — pays with AMIKO tokens");
|
|
@@ -76018,7 +76058,7 @@ function registerServicesCommand(program2) {
|
|
|
76018
76058
|
opts
|
|
76019
76059
|
});
|
|
76020
76060
|
});
|
|
76021
|
-
svc.command("call <method> <path> [body]").description("Call any MPP endpoint —
|
|
76061
|
+
svc.command("call <method> <path> [body]").description("Call any MPP endpoint — pays in AMIKO or USDC on Solana").option("--amiko <amount>", "AMIKO tokens to pay (default: auto-price from USD)").option("--usdc <amount>", "Pay in USDC instead of AMIKO").option("--raw", "Output raw response").action(async (method, path, bodyStr, opts) => {
|
|
76022
76062
|
let body;
|
|
76023
76063
|
if (bodyStr) {
|
|
76024
76064
|
try {
|
|
@@ -76032,7 +76072,8 @@ function registerServicesCommand(program2) {
|
|
|
76032
76072
|
method: method.toUpperCase(),
|
|
76033
76073
|
path,
|
|
76034
76074
|
body,
|
|
76035
|
-
amiko: opts.amiko || "
|
|
76075
|
+
amiko: opts.amiko || (opts.usdc ? undefined : "auto"),
|
|
76076
|
+
usdc: opts.usdc,
|
|
76036
76077
|
opts
|
|
76037
76078
|
});
|
|
76038
76079
|
});
|
|
@@ -76079,11 +76120,15 @@ async function callService(params) {
|
|
|
76079
76120
|
const solanaWallet = allWallets.find((w5) => w5.chain === "solana")?.address;
|
|
76080
76121
|
if (!solanaWallet) {
|
|
76081
76122
|
spinner.stop();
|
|
76082
|
-
console.error(error("No Solana wallet
|
|
76123
|
+
console.error(error("No Solana wallet."));
|
|
76083
76124
|
process.exit(1);
|
|
76084
76125
|
}
|
|
76085
|
-
|
|
76086
|
-
const
|
|
76126
|
+
const token = params.usdc ? "USDC" : "AMIKO";
|
|
76127
|
+
const amount2 = params.usdc || params.amiko || "auto";
|
|
76128
|
+
const { res, txHash, amikoSpent } = await payAndCall(mppBase2, params.method, params.path, billingBase2, billingToken, solanaWallet, token === "USDC" ? amount2 : amount2, params.body, (msg) => {
|
|
76129
|
+
spinner.text = msg;
|
|
76130
|
+
});
|
|
76131
|
+
if (params.usdc) {}
|
|
76087
76132
|
spinner.stop();
|
|
76088
76133
|
if (!res.ok) {
|
|
76089
76134
|
const text = await res.text().catch(() => "");
|
|
@@ -76100,7 +76145,7 @@ async function callService(params) {
|
|
|
76100
76145
|
console.log(JSON.stringify(data, null, 2));
|
|
76101
76146
|
}
|
|
76102
76147
|
console.log("");
|
|
76103
|
-
console.log(success(`Paid ${
|
|
76148
|
+
console.log(success(`Paid ${amikoSpent} ${token}`) + dim(` tx: ${txHash.slice(0, 16)}...`));
|
|
76104
76149
|
} catch (err) {
|
|
76105
76150
|
spinner.stop();
|
|
76106
76151
|
console.error(error(err instanceof Error ? err.message : "Service call failed"));
|