Skip to content
This repository was archived by the owner on Feb 22, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "darchlabs",
"version": "3.6.0",
"version": "3.7.0",
"description": "The DarchLabs client is a Node.js library for interacting with the Synchronizers, Nodes and Jobs APIs. It provides an easy-to-use interface for managing data.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./nodes";
export * from "./synchronizers";
export * from "./smartcontracts";
export * from "./util";
4 changes: 4 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./nodes";
export * from "./network";
export * from "./responses";
export * from "./types";
25 changes: 25 additions & 0 deletions src/nodes/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Subset, type Network } from "../util";

export type NetworkEnvironment =
// | ["ethereum", "mainnet"]
// | ["celo", "mainnet"]
| ["celo", "alfajores"]
// | ["chainlink", "mainnet"]
| ["chainlink", "sepolia"];

export type NetworkEnvironmentKey = Subset<
Network,
// "celo" |
| "alfajores"
// "chainlink" |
| "chainlink_sepolia"
// "ethereum" | "celo" | "alfajores" | "chainlink" | "chainlink_sepolia"
>;

export const NetworksEnvironments: { [K in NetworkEnvironmentKey]: NetworkEnvironment } = {
// ethereum: ["ethereum", "mainnet"],
// celo: ["celo", "mainnet"],
alfajores: ["celo", "alfajores"],
// chainlink: ["chainlink", "mainnet"],
chainlink_sepolia: ["chainlink", "sepolia"],
};
33 changes: 33 additions & 0 deletions src/nodes/nodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import axios from "axios";
import { NodesConfig, type Node, type NodesNetworkEnvironment, NodeInput } from "./types";
import { DeleteNodeResponse, InsertNodeResponse, ListNodesResponse } from "./responses";

export class Nodes {
private baseUrl: string;

constructor(baseUrl: string) {
this.baseUrl = baseUrl;
}

public async insertNode<NE extends NodesNetworkEnvironment>(
input: NodeInput<NodesNetworkEnvironment>
): Promise<InsertNodeResponse<NE>> {
const url = `${this.baseUrl}/api/v2/nodes`;
const { data } = await axios.post<Node<NE>>(url, input);
return { data };
}

public async listNodes(): Promise<ListNodesResponse> {
const url = `${this.baseUrl}/api/v2/nodes`;
const {
data: { nodes },
} = await axios.get<{ nodes: Node<NodesNetworkEnvironment>[] }>(url);
return { data: nodes } as ListNodesResponse;
}

public async deleteNodeById(id: string): Promise<DeleteNodeResponse> {
const url = `${this.baseUrl}/api/v2/nodes`;
await axios.delete(url, { data: { id } });
return {};
}
}
11 changes: 11 additions & 0 deletions src/nodes/responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Node, NodesNetworkEnvironment } from "./types";

export type InsertNodeResponse<NE extends NodesNetworkEnvironment> = {
data: Node<NE>;
};

export type ListNodesResponse = {
data: Node<NodesNetworkEnvironment>[];
};

export type DeleteNodeResponse = {};
66 changes: 66 additions & 0 deletions src/nodes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Subset, type Network } from "../util";
import { NetworkEnvironment } from "./network";

// define node statuses
export type NodeStatus = "running" | "error";

// define [networks,environment] for blockchains
export type NodesEthereumNE = Subset<NetworkEnvironment, ["ethereum", "mainnet"]>;
export type NodesCeloNE = Subset<NetworkEnvironment, ["celo", "mainnet"] | ["celo", "alfajores"]>;
export type NodesChainlinkNE = Subset<NetworkEnvironment, ["chainlink", "mainnet"] | ["chainlink", "sepolia"]>;
export type NodesNetworkEnvironment = NodesEthereumNE | NodesCeloNE | NodesChainlinkNE;

// define celo blockchain implementation
export type NodesCeloConfig<NE extends NodesNetworkEnvironment> = {
ENVIRONMENT: NE[1];
PASSWORD: string;
};

// define celo blockchain environment implementation
export type NodesEthereumConfig<NE extends NodesNetworkEnvironment> = {
ENVIRONMENT: NE[1];
HOST: string;
NETWORK_URL: string;
BASE_CHAIN_DATA_PATH: string;
RPC_PORT: string;
FROM_BLOCK_NUMBER: string;
};

// define chainlink blockchain implemtation
export type NodesChainlinkConfig<NE extends NodesNetworkEnvironment> = {
ENVIRONMENT: NE[1];
ETH_URL: string;
PASSWORD: string;
NODE_EMAIL: string;
NODE_EMAIL_PWD: string;
};

// define node config and input type
export type NodesConfig<NE extends NodesNetworkEnvironment> = NE extends NodesCeloNE
? NodesCeloConfig<NE>
: NE extends NodesEthereumNE
? NodesEthereumConfig<NE>
: NE extends NodesChainlinkNE
? NodesChainlinkConfig<NE>
: never;

export type NodeInput<NE extends NodesNetworkEnvironment> = {
network: NE[0];
envVars: NodesConfig<NE>;
};

// define node type used in api responses
export type Node<NE extends NodesNetworkEnvironment> = {
id: string;
name: string;
network: NE[0];
environment: NE[1];
port: number;
status: NodeStatus;
artifacts: {
Deployments: string[];
Pods: string[];
Services: string[];
};
createdAt: string;
};
2 changes: 1 addition & 1 deletion src/smartcontracts/smartcontracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RestartSmartContractResponse,
} from "./responses";

import type { SmartContractInput } from "./types";
import { type SmartContractInput } from "./types";

export class SmartContracts {
private baseUrl: string;
Expand Down
5 changes: 4 additions & 1 deletion src/smartcontracts/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Event } from "../synchronizers/types";
import { Abi, Network } from "../util";
import { Abi, Network, type Subset } from "../util";

export type SmartContractStatus = "idle" | "running" | "stopping" | "synching" | "stopped" | "error" | "quota_exceeded";

export type SmartContactNetwork = Subset<Network, "ethereum" | "polygon">;
export const SmartContractNetwoks: SmartContactNetwork[] = ["ethereum", "polygon"];

export type SmartContractInput = {
name: string;
network: Network;
Expand Down
1 change: 1 addition & 0 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./abi";
export * from "./get-chain";
export * from "./network";
export * from "./pagination";
export * from "./subset";
88 changes: 75 additions & 13 deletions src/util/network.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,115 @@
export type Network = "ethereum" | "rinkeby" | "goerli" | "polygon" | "mumbai";
export type NetworkType = "evm" | "solana";
export const Networks = [
"ethereum",
"rinkeby",
"goerli",
"sepolia",
"polygon",
"mumbai",
"celo",
"alfajores",
"chainlink",
"chainlink_sepolia",
] as const;
export type Network = (typeof Networks)[number];

export const NetworkType = ["evm", "solana"] as const;
export type NetworkType = (typeof NetworkType)[number];

export const ChainIds: { [key in Network]: number } = {
ethereum: 1,
rinkeby: 4,
goerli: 5,
sepolia: 11155111,
polygon: 137,
mumbai: 80001,
celo: 42220,
alfajores: 44787,
chainlink: 1,
chainlink_sepolia: 11155111,
};

export type Token = "ETH" | "MATIC";
export const Tokens = ["ETH", "MATIC", "CELO", "LINK"] as const;
export type Token = (typeof Tokens)[number];

export type Info = {
name: string;
mainnet: boolean;
baseNetwork: Network;
type: NetworkType;
token: Token;
};

export const Networks: Network[] = ["ethereum", "rinkeby", "goerli", "polygon", "mumbai"];
export const NetworkInfo: {
[key in Network]: {
mainnet: boolean;
baseNetwork: Network;
type: NetworkType;
token: Token;
};
[key in Network]: Info;
} = {
ethereum: {
name: "Ethereum",
mainnet: true,
baseNetwork: "ethereum",
type: "evm",
token: "ETH",
},
rinkeby: {
name: "Ethereum Rinkeby",
mainnet: false,
baseNetwork: "ethereum",
type: "evm",
token: "ETH",
},
goerli: {
name: "Goerli",
mainnet: false,
baseNetwork: "ethereum",
type: "evm",
token: "ETH",
},
sepolia: {
name: "Ethereum Sepolia",
mainnet: false,
baseNetwork: "ethereum",
type: "evm",
token: "ETH",
},
polygon: {
name: "Polygon",
mainnet: true,
baseNetwork: "polygon",
type: "evm",
token: "MATIC",
},
mumbai: {
name: "Polygon Mumbai",
mainnet: false,
baseNetwork: "polygon",
type: "evm",
token: "MATIC",
},
goerli: {
celo: {
name: "Celo",
mainnet: true,
baseNetwork: "celo",
type: "evm",
token: "CELO",
},
alfajores: {
name: "Celo Alfajores",
mainnet: false,
baseNetwork: "ethereum",
baseNetwork: "celo",
type: "evm",
token: "ETH",
token: "CELO",
},
chainlink: {
name: "Chainlink",
mainnet: true,
baseNetwork: "chainlink",
type: "evm",
token: "LINK",
},
chainlink_sepolia: {
name: "Chainlink Sepolia",
mainnet: false,
baseNetwork: "chainlink",
type: "evm",
token: "LINK",
},
};
3 changes: 3 additions & 0 deletions src/util/subset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Subset<T, U> = T extends U ? T : never;

// export type NodesNetwork = Subset<Network, "celo" | "ethereum" | "chainlink">;