mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-08-25 14:08:06 +00:00
require critical auth for order quote
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Auth modes:
|
||||
* Normal (market/token/portfolio): X-APIKEY + timestamp + client_id
|
||||
* Critical (swap, order get/strategy, BSC order quote): normal auth + X-Signature (private key signature)
|
||||
* Critical (swap and order routes): normal auth + X-Signature (private key signature)
|
||||
*/
|
||||
|
||||
import { buildAuthQuery, buildMessage, detectAlgorithm, sign } from "./signer.js";
|
||||
@@ -294,10 +294,7 @@ export class OpenApiClient {
|
||||
slippage: number
|
||||
): Promise<unknown> {
|
||||
const query = { chain, from_address, input_token, output_token, input_amount, slippage };
|
||||
if (chain === "bsc") {
|
||||
return this.criticalRequest("GET", "/v1/trade/quote", query, null);
|
||||
}
|
||||
return this.normalRequest("GET", "/v1/trade/quote", query);
|
||||
return this.criticalRequest("GET", "/v1/trade/quote", query, null);
|
||||
}
|
||||
|
||||
// ---- Swap endpoints (critical auth) ----
|
||||
@@ -369,7 +366,7 @@ export class OpenApiClient {
|
||||
body: unknown
|
||||
): Promise<unknown> {
|
||||
if (!this.privateKeyPem) {
|
||||
throw new Error("GMGN_PRIVATE_KEY is required for critical-auth commands (swap, order get/strategy, and order quote on BSC)");
|
||||
throw new Error("GMGN_PRIVATE_KEY is required for critical-auth commands (swap and all order commands)");
|
||||
}
|
||||
|
||||
return this.executePreparedRequest(() => {
|
||||
|
||||
@@ -75,8 +75,8 @@ export function registerSwapCommands(program: Command): void {
|
||||
|
||||
order
|
||||
.command("quote")
|
||||
.description("Get a swap quote without submitting a transaction (BSC uses critical auth)")
|
||||
.requiredOption("--chain <chain>", "Chain: sol / bsc / base (BSC quote requires GMGN_PRIVATE_KEY)")
|
||||
.description("Get a swap quote without submitting a transaction (requires critical auth)")
|
||||
.requiredOption("--chain <chain>", "Chain: sol / bsc / base (requires GMGN_PRIVATE_KEY)")
|
||||
.requiredOption("--from <address>", "Wallet address (must match API Key binding)")
|
||||
.requiredOption("--input-token <address>", "Input token contract address")
|
||||
.requiredOption("--output-token <address>", "Output token contract address")
|
||||
@@ -89,7 +89,7 @@ export function registerSwapCommands(program: Command): void {
|
||||
validateAddress(opts.inputToken, opts.chain, "--input-token");
|
||||
validateAddress(opts.outputToken, opts.chain, "--output-token");
|
||||
validatePositiveInt(opts.amount, "--amount");
|
||||
const client = new OpenApiClient(getConfig(opts.chain === "bsc"));
|
||||
const client = new OpenApiClient(getConfig(true));
|
||||
const data = await client
|
||||
.quoteOrder(opts.chain, opts.from, opts.inputToken, opts.outputToken, opts.amount, opts.slippage)
|
||||
.catch(exitOnError);
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ export interface Config {
|
||||
|
||||
let _config: Config | null = null;
|
||||
const PRIVATE_KEY_REQUIRED_MSG =
|
||||
"GMGN_PRIVATE_KEY is required for critical-auth commands (swap, order get/strategy, and order quote on BSC)";
|
||||
"GMGN_PRIVATE_KEY is required for critical-auth commands (swap and all order commands)";
|
||||
|
||||
export function getConfig(requirePrivateKey = false): Config {
|
||||
if (_config) {
|
||||
|
||||
Reference in New Issue
Block a user