Skip to content

Commit 8edb5be

Browse files
PaulRBerggavriliumircea
authored andcommitted
refactor: use Shared namespace
1 parent 63d8aed commit 8edb5be

File tree

6 files changed

+74
-73
lines changed

6 files changed

+74
-73
lines changed

src/evm/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AliasMap, ContractBase, ContractMapBase, ManifestBase, Repository, Shared } from "@src/shared/types";
1+
import type { AliasMap, Repository, Shared } from "@src/shared/types";
22
import type * as enums from "./enums";
33

44
export namespace EVM {
@@ -22,7 +22,7 @@ export namespace EVM {
2222
/**
2323
* The base contract type for EVM chains.
2424
*/
25-
export type Contract = ContractBase<Address, Protocol, Version>;
25+
export type Contract = Shared.Contract<Address, Protocol, Version>;
2626

2727
/**
2828
* Reverse mapping of contracts so that we can look up contracts by address.
@@ -36,7 +36,7 @@ export namespace EVM {
3636
};
3737

3838
/** @internal */
39-
export type ContractMap = ContractMapBase<Address>;
39+
export type ContractMap = Shared.ContractMap<Address>;
4040

4141
export type Protocol = `${enums.Protocol}` | enums.Protocol;
4242

@@ -91,7 +91,7 @@ export namespace EVM {
9191
periphery: Standard;
9292
};
9393

94-
export type Standard = ManifestBase;
94+
export type Standard = Shared.Manifest;
9595
}
9696

9797
export type Manifest = Manifest.LockupV1 | Manifest.Standard;

src/internal/factories/resolver.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getContractExplorerURL } from "@src/helpers";
2-
import type { AliasMap, ContractMapBase } from "@src/shared/types";
2+
import type { AliasMap, Shared } from "@src/shared/types";
33
import _ from "lodash";
44

55
/* -------------------------------------------------------------------------- */
@@ -32,7 +32,10 @@ type ContractMapperParams<TProtocol, TVersion> = {
3232
export function createContractMapper<TContract, TProtocol, TVersion, TAddress extends string>(
3333
chainsQueries: ChainsQueries,
3434
) {
35-
return (contractMap: ContractMapBase<TAddress>, params: ContractMapperParams<TProtocol, TVersion>): TContract[] => {
35+
return (
36+
contractMap: Shared.ContractMap<TAddress>,
37+
params: ContractMapperParams<TProtocol, TVersion>,
38+
): TContract[] => {
3639
const { chainId, protocol, version, aliasMap } = params;
3740
const chain = chainsQueries.getOrThrow(chainId);
3841

@@ -74,7 +77,7 @@ export function createStandardDeploymentResolver<TDeployment, TContract, TProtoc
7477
version: TVersion;
7578
chainId: number;
7679
aliasMap: AliasMap;
77-
contractMap: ContractMapBase<TAddress>;
80+
contractMap: Shared.ContractMap<TAddress>;
7881
}): TDeployment => {
7982
const { contractMap, ...baseParams } = params;
8083
const items = contractMapper(contractMap, baseParams);

src/shared/types.ts

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ type ChainBlockExplorer = {
99
apiUrl?: string | undefined;
1010
};
1111

12+
/**
13+
* Repository metadata for Sablier protocol contracts.
14+
*/
15+
export type Repository = {
16+
commit: string;
17+
url: `https://github.com/sablier-labs/${string}`;
18+
};
19+
20+
/**
21+
* Map of contract names to their aliases.
22+
* Used in the Sablier Interface and indexers.
23+
*/
24+
export type AliasMap = {
25+
[contractName: string]: string;
26+
};
27+
1228
export namespace Shared {
1329
/**
1430
* Common properties shared by EVM and Solana chains.
@@ -34,64 +50,46 @@ export namespace Shared {
3450
/** Used in deployment files to identify the chain, e.g., arbitrum-sepolia. */
3551
slug: string;
3652
};
37-
}
38-
39-
/* -------------------------------------------------------------------------- */
40-
41-
/**
42-
* Repository metadata for Sablier protocol contracts.
43-
*/
44-
export type Repository = {
45-
commit: string;
46-
url: `https://github.com/sablier-labs/${string}`;
47-
};
48-
49-
/**
50-
* Map of contract names to their aliases.
51-
* Used in the Sablier Interface and indexers.
52-
*/
53-
export type AliasMap = {
54-
[contractName: string]: string;
55-
};
5653

57-
/**
58-
* Generic contract mapping that supports both simple addresses and address-with-block tuples.
59-
* @internal
60-
*/
61-
export type ContractMapBase<TAddress extends string> = {
62-
[contractName: string]: TAddress | [TAddress, number];
63-
};
54+
/**
55+
* Generic contract mapping that supports both simple addresses and address-with-block tuples.
56+
* @internal
57+
*/
58+
export type ContractMap<TAddress extends string> = {
59+
[contractName: string]: TAddress | [TAddress, number];
60+
};
6461

65-
/**
66-
* Base manifest structure for contract names in a protocol version.
67-
*/
68-
export type ManifestBase = {
69-
[contractKey: string]: string;
70-
};
62+
/**
63+
* Base manifest structure for contract names in a protocol version.
64+
*/
65+
export type Manifest = {
66+
[contractKey: string]: string;
67+
};
7168

72-
/**
73-
* Generic contract type shared across all platforms (EVM, Solana, etc.).
74-
* This provides a consistent interface for contract metadata regardless of the underlying blockchain.
75-
*
76-
* @template TAddress - The address type for the platform (e.g., `0x${string}` for EVM, `string` for Solana)
77-
* @template TProtocol - The protocol enum/type for the platform
78-
* @template TVersion - The version enum/type for the platform
79-
*/
80-
export type ContractBase<TAddress extends string, TProtocol, TVersion> = {
81-
/** The address of the contract. */
82-
address: TAddress;
83-
/** Optional alias for the contract, used in the Sablier Interface and the indexers. */
84-
alias?: string;
85-
/** The block number at which the contract was deployed. */
86-
block?: number;
87-
/** The ID of the chain the contract is deployed on. */
88-
chainId: number;
89-
/** URL to the explorer page for the contract. */
90-
explorerURL?: string;
91-
/** The name of the contract. */
92-
name: string;
93-
/** The protocol the contract is part of (optional). */
94-
protocol: TProtocol | undefined;
95-
/** The release version the contract is part of (optional). */
96-
version: TVersion | undefined;
97-
};
69+
/**
70+
* Generic contract type shared across all platforms (EVM, Solana, etc.).
71+
* This provides a consistent interface for contract metadata regardless of the underlying blockchain.
72+
*
73+
* @template TAddress - The address type for the platform (e.g., `0x${string}` for EVM, `string` for Solana)
74+
* @template TProtocol - The protocol enum/type for the platform
75+
* @template TVersion - The version enum/type for the platform
76+
*/
77+
export type Contract<TAddress extends string, TProtocol, TVersion> = {
78+
/** The address of the contract. */
79+
address: TAddress;
80+
/** Optional alias for the contract, used in the Sablier Interface and the indexers. */
81+
alias?: string;
82+
/** The block number at which the contract was deployed. */
83+
block?: number;
84+
/** The ID of the chain the contract is deployed on. */
85+
chainId: number;
86+
/** URL to the explorer page for the contract. */
87+
explorerURL?: string;
88+
/** The name of the contract. */
89+
name: string;
90+
/** The protocol the contract is part of (optional). */
91+
protocol: TProtocol | undefined;
92+
/** The release version the contract is part of (optional). */
93+
version: TVersion | undefined;
94+
};
95+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SablierMerkleInstantV10IDL } from "@src/solana/idl/airdrops/v1.0";
1+
import { idl as SablierMerkleInstantIDL } from "@src/solana/idl/airdrops/v1.0/SablierMerkleInstant/idl";
22
import type { Sablier } from "@src/types";
33
import manifest from "./manifest";
44

55
export const idl: Sablier.Solana.IdlMap = {
6-
[manifest.SABLIER_MERKLE_INSTANT]: SablierMerkleInstantV10IDL,
6+
[manifest.SABLIER_MERKLE_INSTANT]: SablierMerkleInstantIDL,
77
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SablierLockupLinearV10IDL } from "@src/solana/idl/lockup/v1.0";
1+
import { idl as SablierLockupLinearIDL } from "@src/solana/idl/lockup/v1.0/SablierLockupLinear/idl";
22
import type { Sablier } from "@src/types";
33
import manifest from "./manifest";
44

55
export const idl: Sablier.Solana.IdlMap = {
6-
[manifest.SABLIER_LOCKUP_LINEAR]: SablierLockupLinearV10IDL,
6+
[manifest.SABLIER_LOCKUP_LINEAR]: SablierLockupLinearIDL,
77
};

src/solana/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AliasMap, ContractBase, ContractMapBase, ManifestBase, Repository, Shared } from "@src/shared/types";
1+
import type { AliasMap, Repository, Shared } from "@src/shared/types";
22
import type * as enums from "./enums";
33

44
export namespace Solana {
@@ -25,9 +25,9 @@ export namespace Solana {
2525
/**
2626
* The base contract type for Solana.
2727
*/
28-
export type Program = ContractBase<Address, Protocol, Version>;
28+
export type Program = Shared.Contract<Address, Protocol, Version>;
2929

30-
export type ProgramMap = ContractMapBase<Address>;
30+
export type ProgramMap = Shared.ContractMap<Address>;
3131
export type ProgramCatalog = {
3232
[protocol in Protocol]: {
3333
[chainId: number]: {
@@ -49,7 +49,7 @@ export namespace Solana {
4949
/**
5050
* Contract names for a given protocol and version.
5151
*/
52-
export type Manifest = ManifestBase;
52+
export type Manifest = Shared.Manifest;
5353

5454
export type Protocol = `${enums.Protocol}` | enums.Protocol;
5555

0 commit comments

Comments
 (0)