Skip to content

Commit c8394d7

Browse files
committed
refactor: extract EVM types to dedicated module
Move EVM-specific type definitions from src/types.ts to src/evm/types.ts for better code organization. Update imports across affected files while maintaining backward compatibility through re-exports.
1 parent 100e2a5 commit c8394d7

File tree

3 files changed

+232
-268
lines changed

3 files changed

+232
-268
lines changed

src/evm/types.ts

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
import type { Chain as ViemChain } from "viem";
2+
import type * as enums from "./enums";
3+
4+
/**
5+
* @see https://github.com/wevm/viem/discussions/3678
6+
*/
7+
type ChainBlockExplorer = {
8+
name: string;
9+
url: string;
10+
apiUrl?: string | undefined;
11+
};
12+
13+
type Repository = {
14+
commit: string;
15+
url: `https://github.com/sablier-labs/${string}`;
16+
};
17+
18+
export namespace EVM {
19+
export type AliasMap = { [contractName: string]: string };
20+
/** Ethereum address in the format 0x followed by 40 hex characters. */
21+
export type Address = `0x${string}`;
22+
23+
export type AbiMap = { [contractName: string]: readonly object[] };
24+
export type Chain = ViemChain & {
25+
blockExplorers: {
26+
[key: string]: ChainBlockExplorer;
27+
default: ChainBlockExplorer;
28+
};
29+
/** Whether this chain is supported by the Sablier Interface at https://app.sablier.com. */
30+
isSupportedByUI: boolean;
31+
/** Whether this is a testnet network. */
32+
isTestnet: boolean;
33+
/** Whether this is a zkEVM like zkSync. */
34+
isZK: boolean;
35+
nativeCurrency: ViemChain["nativeCurrency"] & {
36+
coinGeckoId: string;
37+
};
38+
rpc: {
39+
/** Alchemy RPC URL generator. */
40+
alchemy?: (apiKey: string) => string;
41+
/** Default RPC URL. */
42+
defaults: string[];
43+
/** Infura RPC URL generator. */
44+
infura?: (apiKey: string) => string;
45+
/** RouteMesh RPC URL generator. */
46+
routemesh?: (apiKey: string) => string;
47+
};
48+
/** Used in deployment files to identify the chain, e.g., arbitrum-sepolia. */
49+
slug: string;
50+
};
51+
52+
/**
53+
* The base contract type.
54+
*/
55+
export type Contract = {
56+
/** The address of the contract. */
57+
address: Address;
58+
/** Optional alias for the contract, used in the Sablier Interface and the indexers. */
59+
alias?: string;
60+
/** The block number at which the contract was deployed. */
61+
block?: number;
62+
/** The ID of the chain the contract is deployed on. */
63+
chainId: number;
64+
/** URL to the explorer page for the contract. */
65+
explorerURL?: string;
66+
/** The name of the contract. */
67+
name: string;
68+
/** The protocol the contract is part of (optional). */
69+
protocol: EVM.Protocol | undefined;
70+
/** The release version the contract is part of (optional). */
71+
version: EVM.Version | undefined;
72+
};
73+
74+
/**
75+
* Reverse mapping of contracts so that we can look up contracts by address.
76+
*/
77+
export type ContractCatalog = {
78+
[protocol in Protocol]: {
79+
[chainId: number]: {
80+
[address: Address]: Contract;
81+
};
82+
};
83+
};
84+
85+
/** @internal */
86+
export type ContractMap = {
87+
[contractName: string]: Address | [Address, number];
88+
};
89+
90+
export type Protocol = `${enums.Protocol}` | enums.Protocol;
91+
92+
export type CompilerSettings = {
93+
/** The EVM version such as shanghai, paris, etc. */
94+
evmVersion: string;
95+
/** Whether the optimizer is enabled. */
96+
optimizer: boolean;
97+
/** The number of optimizer runs. */
98+
optimizerRuns: number;
99+
/** Optional salt used for CREATE2 deployment. None implies deployment using CREATE. */
100+
salt?: string;
101+
/** The solc version used. */
102+
solcVersion: `v${number}.${number}.${number}`;
103+
/** Whether the IR is used. */
104+
viaIR: boolean;
105+
/** Optional zk version used, only valid for zkEVM chains. */
106+
zkVersion?: `v${number}.${number}.${number}`;
107+
};
108+
109+
/* -------------------------------------------------------------------------- */
110+
/* DEPLOYMENT */
111+
/* -------------------------------------------------------------------------- */
112+
113+
export namespace Deployment {
114+
export type Standard = {
115+
chainId: number;
116+
contracts: Contract[];
117+
/** TODO: Compiler settings for the contract. Not implemented yet. */
118+
compilerSettings?: CompilerSettings;
119+
};
120+
121+
export type LockupV1 = Standard & {
122+
core: Contract[];
123+
periphery: Contract[];
124+
};
125+
}
126+
127+
export type Deployment = Deployment.Standard | Deployment.LockupV1;
128+
129+
/* -------------------------------------------------------------------------- */
130+
/* MANIFEST */
131+
/* -------------------------------------------------------------------------- */
132+
133+
/**
134+
* Contract names for a given protocol and version.
135+
* Note that this may contain both deployed contracts and abstract contracts that are not deployed.
136+
*/
137+
export namespace Manifest {
138+
export type LockupV1 = {
139+
core: Standard;
140+
periphery: Standard;
141+
};
142+
143+
export type Standard = {
144+
[contractKey: string]: string;
145+
};
146+
}
147+
148+
export type Manifest = Manifest.LockupV1 | Manifest.Standard;
149+
150+
/* -------------------------------------------------------------------------- */
151+
/* RELEASE */
152+
/* -------------------------------------------------------------------------- */
153+
154+
/**
155+
* A collection of deployments for a given protocol and version.
156+
*/
157+
export namespace Release {
158+
type Common = {
159+
abi: AbiMap;
160+
/** A map of contract names to their aliases, used in the Sablier Interface and the Graph. */
161+
aliases?: AliasMap;
162+
/** An array of contract names. */
163+
contractNames: string[];
164+
/** Whether this is the latest release for this protocol. */
165+
isLatest: boolean;
166+
/** The kind of release. */
167+
kind: "standard" | "lockupV1";
168+
/** The Sablier protocol released, e.g. `airdrops`. */
169+
protocol: Protocol;
170+
/** Repository information for the release. */
171+
repository?: Repository;
172+
/** The version of the release, e.g., `v1.3`. */
173+
version: Version;
174+
};
175+
176+
/**
177+
* Lockup v1.x release used to separate Lockup contracts into core and periphery sub-categories.
178+
* @see https://github.com/sablier-labs/v2-periphery
179+
*/
180+
export type LockupV1 = Common & {
181+
deployments: Deployment.LockupV1[];
182+
kind: "lockupV1";
183+
manifest: Manifest.LockupV1;
184+
};
185+
186+
export type Standard = Common & {
187+
deployments: Deployment.Standard[];
188+
kind: "standard";
189+
manifest: Manifest.Standard;
190+
};
191+
}
192+
193+
export type Release = Release.Standard | Release.LockupV1;
194+
195+
/* -------------------------------------------------------------------------- */
196+
/* VERSION */
197+
/* -------------------------------------------------------------------------- */
198+
199+
export namespace Version {
200+
export type Airdrops = `${enums.Version.Airdrops}` | enums.Version.Airdrops;
201+
202+
export type Flow = `${enums.Version.Flow}` | enums.Version.Flow;
203+
204+
export type Legacy = `${enums.Version.Legacy}` | enums.Version.Legacy;
205+
206+
export type Lockup = `${enums.Version.Lockup}` | enums.Version.Lockup;
207+
}
208+
export type Version = Version.Airdrops | Version.Flow | Version.Legacy | Version.Lockup;
209+
}

src/sablier.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* ```typescript
77
* import { sablier } from "sablier";
88
*
9-
* // New API (preferred)
10-
* const lockupContract = sablier.evm.contracts.get({
9+
* // EVM
10+
* let lockupContract = sablier.evm.contracts.get({
1111
* chainId: mainnet.id,
1212
* contractName: "SablierLockup",
1313
* release: releases.lockup["v2.0"],
1414
* });
1515
*
16-
* // Old API (backward compatible, deprecated)
17-
* const lockupContract = sablier.contracts.get({
16+
* // Can also be accessed like this:
17+
* lockupContract = sablier.contracts.get({
1818
* chainId: mainnet.id,
1919
* contractName: "SablierLockup",
2020
* release: releases.lockup["v2.0"],
@@ -28,6 +28,9 @@ import { chainsQueries as evmChainsQueries } from "./evm/chains/queries";
2828
import { contractsQueries as evmContractsQueries } from "./evm/contracts/queries";
2929
import { releasesQueries as evmReleasesQueries } from "./evm/releases/queries";
3030

31+
/**
32+
* Has to be defined here to avoid circular dependencies.
33+
*/
3134
const evmDeploymentsQueries = {
3235
/**
3336
* Get many deployments.
@@ -51,10 +54,6 @@ const evm = {
5154
};
5255

5356
export const sablier = {
54-
// Kept like this for backwards compatibility
55-
chains: evm.chains,
56-
contract: evm.contracts,
57-
deployments: evm.deployments,
57+
...evm, // re-exporting for backward compatibility
5858
evm,
59-
releases: evm.releases,
6059
};

0 commit comments

Comments
 (0)