-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathkit.ts
More file actions
59 lines (49 loc) · 1.81 KB
/
Copy pathkit.ts
File metadata and controls
59 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
InterfaceCommunicator,
AutomationContext,
PublicDeployer,
CoreActions,
} from "./helpers";
import { Address, Communicator, Methods, UserClientFactory } from "./types";
import { ADDRESSES, AddressRegistry, ConsoleContractNames } from "./constants";
export default class ConsoleKit {
public readonly automationContext: AutomationContext;
public readonly publicDeployer: PublicDeployer;
public readonly coreActions: CoreActions;
private readonly communicator: Communicator;
private readonly apiKey: string;
private readonly baseURL: string;
private readonly addressRegistry: AddressRegistry;
constructor(apiKey: string, baseURL: string) {
this.validateInputs(apiKey, baseURL);
this.apiKey = apiKey;
this.baseURL = baseURL;
this.addressRegistry = this.determineAddressRegistry(baseURL);
this.communicator = new InterfaceCommunicator();
this.publicDeployer = new PublicDeployer(this.apiKey, this.baseURL);
this.automationContext = new AutomationContext(this.apiKey, this.baseURL);
this.coreActions = new CoreActions(this.apiKey, this.baseURL);
}
private validateInputs(apiKey: string, baseURL: string): void {
if (!apiKey) {
throw new Error("API key is required");
}
if (!baseURL) {
throw new Error("Base URL is required");
}
}
private determineAddressRegistry(baseURL: string): AddressRegistry {
return baseURL.includes("dev") ? ADDRESSES.DEV : ADDRESSES.PROD;
}
getContractAddress(contractName: ConsoleContractNames): Address {
return this.addressRegistry[contractName];
}
async getClientFactory(): Promise<UserClientFactory> {
const response = await this.communicator.send<
Methods.getClientFactory,
undefined,
UserClientFactory
>(Methods.getClientFactory, undefined);
return response.data;
}
}