degate-cli 1.0.2 → 1.0.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.
- package/cli.js +16 -4
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -404,9 +404,6 @@ async function intentTryCreate(client, order) {
|
|
|
404
404
|
const resp = await client.post('/order-book-api/intent/v2/compact_try_create', order, {
|
|
405
405
|
headers: { Version: '0.0.1' },
|
|
406
406
|
});
|
|
407
|
-
if (!resp.data?.result) {
|
|
408
|
-
console.log(chalk.yellow('[DEBUG] compact_try_create raw resp.data:'), JSON.stringify(resp.data, null, 2));
|
|
409
|
-
}
|
|
410
407
|
return resp.data;
|
|
411
408
|
}
|
|
412
409
|
|
|
@@ -430,7 +427,22 @@ function verifyApiSign(message, sig) {
|
|
|
430
427
|
|
|
431
428
|
async function signAndSubmitIntent(client, tryResp, mnemonic, das) {
|
|
432
429
|
const intentItem = tryResp.result;
|
|
433
|
-
if (!intentItem)
|
|
430
|
+
if (!intentItem) {
|
|
431
|
+
// 余额不足时后端返回 result: null,给出明确提示
|
|
432
|
+
if (tryResp.is_balance_enough === false || tryResp.is_gas_pay_token_enough === false) {
|
|
433
|
+
const needed = tryResp.gas_pay_token_needed;
|
|
434
|
+
const avail = tryResp.gas_pay_token_avail;
|
|
435
|
+
const needAmt = needed?.amount ? (parseInt(needed.amount) / 1e9).toFixed(6) : '?';
|
|
436
|
+
const availAmt = avail?.amount ? (parseInt(avail.amount) / 1e9).toFixed(6) : '0';
|
|
437
|
+
const tokenSymbol = needed?.token === 'So11111111111111111111111111111111111111112' ? 'SOL' : (needed?.token || 'gas token');
|
|
438
|
+
throw new Error(
|
|
439
|
+
`余额不足\n` +
|
|
440
|
+
` ${tryResp.is_balance_enough === false ? '❌ USDC 余额不足' : ''}\n` +
|
|
441
|
+
` ${tryResp.is_gas_pay_token_enough === false ? `❌ Gas 不足: 需要 ${needAmt} ${tokenSymbol},账户有 ${availAmt} ${tokenSymbol}` : ''}`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
throw new Error('compact_try_create 未返回 result');
|
|
445
|
+
}
|
|
434
446
|
|
|
435
447
|
if (!verifyApiSign(intentItem.data, intentItem.signature)) {
|
|
436
448
|
throw new Error('API 签名验证失败');
|