mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 16:58:08 +00:00
feat: 更新 LighterSigner 配置,baseUrl 变为可选以支持离线签名和测试
This commit is contained in:
@@ -7,7 +7,7 @@ export interface LighterSignerConfig {
|
|||||||
accountIndex: number | bigint;
|
accountIndex: number | bigint;
|
||||||
chainId: number;
|
chainId: number;
|
||||||
apiKeys: Record<number, string>;
|
apiKeys: Record<number, string>;
|
||||||
baseUrl: string;
|
baseUrl?: string; // optional for offline signing/tests
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseSignOptions {
|
interface BaseSignOptions {
|
||||||
@@ -142,14 +142,12 @@ export class LighterSigner {
|
|||||||
private readonly ready: Promise<void>;
|
private readonly ready: Promise<void>;
|
||||||
|
|
||||||
constructor(config: LighterSignerConfig) {
|
constructor(config: LighterSignerConfig) {
|
||||||
if (!config.baseUrl) {
|
|
||||||
throw new Error("LighterSigner requires baseUrl for signer bridge");
|
|
||||||
}
|
|
||||||
this.accountIndex = typeof config.accountIndex === "number"
|
this.accountIndex = typeof config.accountIndex === "number"
|
||||||
? BigInt(Math.trunc(config.accountIndex))
|
? BigInt(Math.trunc(config.accountIndex))
|
||||||
: config.accountIndex;
|
: config.accountIndex;
|
||||||
this.chainId = config.chainId >>> 0;
|
this.chainId = config.chainId >>> 0;
|
||||||
this.baseUrl = config.baseUrl;
|
// Default to localhost to allow offline signing in tests
|
||||||
|
this.baseUrl = config.baseUrl ?? "http://localhost";
|
||||||
|
|
||||||
const entries = Object.entries(config.apiKeys ?? {});
|
const entries = Object.entries(config.apiKeys ?? {});
|
||||||
if (!entries.length) {
|
if (!entries.length) {
|
||||||
@@ -157,15 +155,19 @@ export class LighterSigner {
|
|||||||
}
|
}
|
||||||
this.defaultKeyIndex = Number(entries[0]![0]);
|
this.defaultKeyIndex = Number(entries[0]![0]);
|
||||||
|
|
||||||
this.bridge = new PythonSignerBridge(resolveScriptPath());
|
const bridge = new PythonSignerBridge(resolveScriptPath());
|
||||||
|
this.bridge = bridge;
|
||||||
|
const baseUrl = this.baseUrl;
|
||||||
|
const chainId = this.chainId;
|
||||||
|
const accountIndexStr = this.accountIndex.toString();
|
||||||
this.ready = (async () => {
|
this.ready = (async () => {
|
||||||
for (const [index, key] of entries) {
|
for (const [index, key] of entries) {
|
||||||
await this.bridge.call("create_client", {
|
await bridge.call("create_client", {
|
||||||
apiKeyIndex: Number(index),
|
apiKeyIndex: Number(index),
|
||||||
privateKey: key,
|
privateKey: key,
|
||||||
baseUrl: this.baseUrl,
|
baseUrl,
|
||||||
chainId: this.chainId,
|
chainId,
|
||||||
accountIndex: this.accountIndex.toString(),
|
accountIndex: accountIndexStr,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user