@obolnetwork/obol-sdk 2.4.3 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,11 +1,4 @@
1
- import {
2
- ZeroAddress,
3
- type Provider,
4
- type Signer,
5
- type JsonRpcSigner,
6
- type JsonRpcProvider,
7
- type JsonRpcApiProvider,
8
- } from 'ethers';
1
+ import { ZeroAddress } from 'ethers';
9
2
  import { v4 as uuidv4 } from 'uuid';
10
3
  import { Base } from './base.js';
11
4
  import {
@@ -37,6 +30,8 @@ import {
37
30
  type ClusterValidator,
38
31
  type ETH_ADDRESS,
39
32
  type OWRTranches,
33
+ type ProviderType,
34
+ type SignerType,
40
35
  } from './types.js';
41
36
  import { clusterConfigOrDefinitionHash } from './verification/common.js';
42
37
  import { validatePayload } from './ajv.js';
@@ -59,19 +54,28 @@ export * from './types.js';
59
54
  export * from './services.js';
60
55
  export * from './verification/signature-validator.js';
61
56
  export * from './verification/common.js';
57
+ export { Incentives } from './incentives.js';
62
58
 
63
59
  /**
64
60
  * Obol sdk Client can be used for creating, managing and activating distributed validators.
65
61
  */
66
62
  export class Client extends Base {
67
- private readonly signer: Signer | JsonRpcSigner | undefined;
63
+ /**
64
+ * The signer used for signing transactions.
65
+ */
66
+ private readonly signer: SignerType | undefined;
67
+
68
+ /**
69
+ * The incentives module, responsible for managing Obol tokens distribution.
70
+ * @type {Incentives}
71
+ */
68
72
  public incentives: Incentives;
69
- public provider:
70
- | Provider
71
- | JsonRpcProvider
72
- | JsonRpcApiProvider
73
- | undefined
74
- | null;
73
+
74
+ /**
75
+ * The blockchain provider, used to interact with the network.
76
+ * It can be null, undefined, or a valid provider instance and defaults to the Signer provider if Signer is passed.
77
+ */
78
+ public provider: ProviderType | undefined | null;
75
79
 
76
80
  /**
77
81
  * @param config - Client configurations
@@ -85,8 +89,8 @@ export class Client extends Base {
85
89
  */
86
90
  constructor(
87
91
  config: { baseUrl?: string; chainId?: number },
88
- signer?: Signer | JsonRpcSigner,
89
- provider?: Provider | JsonRpcProvider,
92
+ signer?: SignerType,
93
+ provider?: ProviderType,
90
94
  ) {
91
95
  super(config);
92
96
  this.signer = signer;
@@ -98,7 +102,7 @@ export class Client extends Base {
98
102
  this.signer,
99
103
  this.chainId,
100
104
  this.request.bind(this),
101
- (this.provider = provider),
105
+ this.provider,
102
106
  );
103
107
  }
104
108
 
@@ -201,19 +205,19 @@ export class Client extends Base {
201
205
 
202
206
  const checkSplitMainAddress = await isContractAvailable(
203
207
  CHAIN_CONFIGURATION[this.chainId].SPLITMAIN_ADDRESS.address,
204
- this.signer.provider as Provider,
208
+ this.signer.provider as ProviderType,
205
209
  CHAIN_CONFIGURATION[this.chainId].SPLITMAIN_ADDRESS.bytecode,
206
210
  );
207
211
 
208
212
  const checkMulticallAddress = await isContractAvailable(
209
213
  CHAIN_CONFIGURATION[this.chainId].MULTICALL_ADDRESS.address,
210
- this.signer.provider as Provider,
214
+ this.signer.provider as ProviderType,
211
215
  CHAIN_CONFIGURATION[this.chainId].MULTICALL_ADDRESS.bytecode,
212
216
  );
213
217
 
214
218
  const checkOWRFactoryAddress = await isContractAvailable(
215
219
  CHAIN_CONFIGURATION[this.chainId].OWR_FACTORY_ADDRESS.address,
216
- this.signer.provider as Provider,
220
+ this.signer.provider as ProviderType,
217
221
  CHAIN_CONFIGURATION[this.chainId].OWR_FACTORY_ADDRESS.bytecode,
218
222
  );
219
223
 
@@ -251,7 +255,7 @@ export class Client extends Base {
251
255
 
252
256
  const isSplitterDeployed = await isContractAvailable(
253
257
  predictedSplitterAddress,
254
- this.signer.provider as Provider,
258
+ this.signer.provider as ProviderType,
255
259
  );
256
260
 
257
261
  const { withdrawal_address, fee_recipient_address } =
@@ -316,7 +320,7 @@ export class Client extends Base {
316
320
 
317
321
  const checkSplitMainAddress = await isContractAvailable(
318
322
  CHAIN_CONFIGURATION[this.chainId].SPLITMAIN_ADDRESS.address,
319
- this.signer.provider as Provider,
323
+ this.signer.provider as ProviderType,
320
324
  CHAIN_CONFIGURATION[this.chainId].SPLITMAIN_ADDRESS.bytecode,
321
325
  );
322
326
 
@@ -349,7 +353,7 @@ export class Client extends Base {
349
353
 
350
354
  const isSplitterDeployed = await isContractAvailable(
351
355
  predictedSplitterAddress,
352
- this.signer.provider as Provider,
356
+ this.signer.provider as ProviderType,
353
357
  );
354
358
 
355
359
  if (!isSplitterDeployed) {
@@ -3,14 +3,9 @@ import {
3
3
  type ClusterValidator,
4
4
  type ETH_ADDRESS,
5
5
  type SplitRecipient,
6
+ type SignerType,
6
7
  } from './types';
7
- import {
8
- Contract,
9
- Interface,
10
- parseEther,
11
- ZeroAddress,
12
- type Signer,
13
- } from 'ethers';
8
+ import { Contract, Interface, parseEther, ZeroAddress } from 'ethers';
14
9
  import { OWRContract, OWRFactoryContract } from './abi/OWR';
15
10
  import { splitMainEthereumAbi } from './abi/SplitMain';
16
11
  import { MultiCallContract } from './abi/Multicall';
@@ -59,7 +54,7 @@ export const predictSplitterAddress = async ({
59
54
  distributorFee,
60
55
  controllerAddress,
61
56
  }: {
62
- signer: Signer;
57
+ signer: SignerType;
63
58
  accounts: ETH_ADDRESS[];
64
59
  percentAllocations: number[];
65
60
  chainId: number;
@@ -111,7 +106,7 @@ export const handleDeployOWRAndSplitter = async ({
111
106
  controllerAddress,
112
107
  recoveryAddress,
113
108
  }: {
114
- signer: Signer;
109
+ signer: SignerType;
115
110
  isSplitterDeployed: boolean;
116
111
  predictedSplitterAddress: ETH_ADDRESS;
117
112
  accounts: ETH_ADDRESS[];
@@ -174,7 +169,7 @@ const createOWRContract = async ({
174
169
  chainId,
175
170
  }: {
176
171
  owrArgs: OWRArgs;
177
- signer: Signer;
172
+ signer: SignerType;
178
173
  chainId: number;
179
174
  }): Promise<ETH_ADDRESS> => {
180
175
  try {
@@ -209,7 +204,7 @@ export const deploySplitterContract = async ({
209
204
  distributorFee,
210
205
  controllerAddress,
211
206
  }: {
212
- signer: Signer;
207
+ signer: SignerType;
213
208
  accounts: ETH_ADDRESS[];
214
209
  percentAllocations: number[];
215
210
  chainId: number;
@@ -247,7 +242,7 @@ export const deploySplitterAndOWRContracts = async ({
247
242
  }: {
248
243
  owrArgs: OWRArgs;
249
244
  splitterArgs: SplitArgs;
250
- signer: Signer;
245
+ signer: SignerType;
251
246
  chainId: number;
252
247
  }): Promise<{ owrAddress: ETH_ADDRESS; splitterAddress: ETH_ADDRESS }> => {
253
248
  const executeCalls: Call[] = [];
@@ -304,7 +299,7 @@ export const getOWRTranches = async ({
304
299
  signer,
305
300
  }: {
306
301
  owrAddress: ETH_ADDRESS;
307
- signer: Signer;
302
+ signer: SignerType;
308
303
  }): Promise<OWRTranches> => {
309
304
  const owrContract = new Contract(owrAddress, OWRContract.abi, signer);
310
305
  const res = await owrContract.getTranches();
@@ -318,7 +313,7 @@ export const getOWRTranches = async ({
318
313
 
319
314
  export const multicall = async (
320
315
  calls: Call[],
321
- signer: Signer,
316
+ signer: SignerType,
322
317
  multicallAddress: string,
323
318
  ): Promise<any> => {
324
319
  const multiCallContractInstance = new Contract(
package/src/types.ts CHANGED
@@ -1,3 +1,12 @@
1
+ import {
2
+ type ethers,
3
+ type JsonRpcApiProvider,
4
+ type JsonRpcProvider,
5
+ type JsonRpcSigner,
6
+ type Provider,
7
+ type Signer,
8
+ } from 'ethers';
9
+
1
10
  /**
2
11
  * Permitted ChainID's
3
12
  */
@@ -21,28 +30,14 @@ export enum FORK_MAPPING {
21
30
  '0x10000910' = 560048,
22
31
  }
23
32
 
24
- /**
25
- * Permitted Chain Names
26
- */
27
33
  export const FORK_NAMES: Record<number, string> = {
28
- /** Mainnet. */
29
34
  [FORK_MAPPING['0x00000000']]: 'mainnet',
30
-
31
- /** Goerli/Prater. */
32
35
  [FORK_MAPPING['0x00001020']]: 'goerli',
33
-
34
- /** Gnosis Chain. */
35
36
  [FORK_MAPPING['0x00000064']]: 'gnosis',
36
-
37
- /** Holesky. */
38
37
  [FORK_MAPPING['0x01017000']]: 'holesky',
39
-
40
- /** Sepolia. */
41
38
  [FORK_MAPPING['0x90000069']]: 'sepolia',
42
-
43
- /** Hoodi. */
44
39
  [FORK_MAPPING['0x10000910']]: 'hoodi',
45
- };
40
+ } as const;
46
41
 
47
42
  /**
48
43
  * Node operator data
@@ -323,3 +318,22 @@ export type Incentives = {
323
318
  * String expected to be Ethereum Address
324
319
  */
325
320
  export type ETH_ADDRESS = string;
321
+
322
+ /**
323
+ * Provider Types
324
+ */
325
+ export type ProviderType =
326
+ | Provider
327
+ | JsonRpcProvider
328
+ | JsonRpcApiProvider
329
+ | ethers.BrowserProvider;
330
+
331
+ /**
332
+ * Signer Types
333
+ */
334
+ export type SignerType = Signer | JsonRpcSigner;
335
+
336
+ /**
337
+ * claimIncentives Response
338
+ */
339
+ export type ClaimIncentivesResponse = { txHash: string | null };
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { ethers, type Provider } from 'ethers';
1
+ import { ethers } from 'ethers';
2
2
  import { DefinitionFlow, PROVIDER_MAP } from './constants';
3
- import { FORK_NAMES, type ClusterDefinition } from './types';
3
+ import { FORK_NAMES, type ProviderType, type ClusterDefinition } from './types';
4
4
 
5
5
  export const hexWithout0x = (hex: string): string => {
6
6
  return hex.slice(2, hex.length);
@@ -58,14 +58,14 @@ export const definitionFlow = (
58
58
 
59
59
  export const findDeployedBytecode = async (
60
60
  contractAddress: string,
61
- provider: Provider,
61
+ provider: ProviderType,
62
62
  ): Promise<string> => {
63
63
  return await provider?.getCode(contractAddress);
64
64
  };
65
65
 
66
66
  export const isContractAvailable = async (
67
67
  contractAddress: string,
68
- provider: Provider,
68
+ provider: ProviderType,
69
69
  bytecode?: string,
70
70
  ): Promise<boolean> => {
71
71
  const code = await findDeployedBytecode(contractAddress, provider);
@@ -76,7 +76,7 @@ export const isContractAvailable = async (
76
76
  return !!code && code !== '0x' && code !== '0x0';
77
77
  };
78
78
 
79
- export const getProvider = (chainId: number): ethers.Provider => {
79
+ export const getProvider = (chainId: number): ethers.JsonRpcProvider => {
80
80
  const rpcUrl = PROVIDER_MAP[chainId];
81
81
  if (!rpcUrl || rpcUrl === 'undefined') {
82
82
  throw new Error(`No provider configured for ${FORK_NAMES[chainId]}`);