genlayer-js 0.18.4 → 0.18.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/CLAUDE.md +66 -0
  3. package/README.md +52 -1
  4. package/dist/chains/index.cjs +2 -2
  5. package/dist/chains/index.d.cts +2 -2
  6. package/dist/chains/index.d.ts +2 -2
  7. package/dist/chains/index.js +1 -1
  8. package/dist/{chains-BIe_Q0mF.d.cts → chains-B7B7UXdn.d.cts} +6 -2
  9. package/dist/{chains-BIe_Q0mF.d.ts → chains-B7B7UXdn.d.ts} +6 -2
  10. package/dist/{chunk-NO75TOQL.js → chunk-NZI52PRP.js} +532 -4
  11. package/dist/{chunk-SMGWE7OH.cjs → chunk-TBF5WZHL.cjs} +533 -5
  12. package/dist/{index-C5zeayBB.d.cts → index-BVDASTaU.d.cts} +1 -1
  13. package/dist/index-DPyenUTZ.d.ts +1380 -0
  14. package/dist/index-Dfaw9WiR.d.cts +1380 -0
  15. package/dist/{index-BpFWfpio.d.ts → index-ucNO2REF.d.ts} +1 -1
  16. package/dist/index.cjs +540 -38
  17. package/dist/index.d.cts +17 -5
  18. package/dist/index.d.ts +17 -5
  19. package/dist/index.js +517 -15
  20. package/dist/types/index.cjs +2 -2
  21. package/dist/types/index.d.cts +2 -2
  22. package/dist/types/index.d.ts +2 -2
  23. package/dist/types/index.js +1 -1
  24. package/package.json +1 -1
  25. package/src/abi/index.ts +1 -0
  26. package/src/abi/staking.ts +518 -0
  27. package/src/chains/localnet.ts +2 -1
  28. package/src/chains/studionet.ts +1 -0
  29. package/src/chains/testnetAsimov.ts +10 -3
  30. package/src/client/client.ts +17 -15
  31. package/src/index.ts +1 -0
  32. package/src/staking/actions.ts +598 -0
  33. package/src/staking/index.ts +2 -0
  34. package/src/staking/utils.ts +22 -0
  35. package/src/types/chains.ts +6 -2
  36. package/src/types/clients.ts +6 -6
  37. package/src/types/index.ts +1 -0
  38. package/src/types/staking.ts +228 -0
  39. package/tsconfig.vitest-temp.json +41 -0
  40. package/dist/index-B2AY6_eD.d.ts +0 -407
  41. package/dist/index-BYma5s90.d.cts +0 -407
  42. /package/dist/{chunk-FPZNF3JH.cjs → chunk-W4V73RPN.cjs} +0 -0
  43. /package/dist/{chunk-47QDX7IX.js → chunk-ZHBOSLFN.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
 
2
2
 
3
+ ## 0.18.5 (2025-12-03)
4
+
3
5
  ## 0.18.4 (2025-11-11)
4
6
 
5
7
 
package/CLAUDE.md ADDED
@@ -0,0 +1,66 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Build & Development
6
+
7
+ ```bash
8
+ npm install # Install dependencies
9
+ npm run build # Production build (tsup, outputs ESM+CJS to dist/)
10
+ npm run build:watch # Watch mode for development
11
+ npm run lint # ESLint with auto-fix
12
+ npm link # Link package locally for testing in other projects
13
+ ```
14
+
15
+ ## Testing
16
+
17
+ ```bash
18
+ npm test # Run tests with typecheck (vitest)
19
+ npm run test:watch # Watch mode
20
+ ```
21
+
22
+ ## Architecture
23
+
24
+ ### Module Structure & Exports
25
+
26
+ The SDK exports three entry points (see `package.json` exports):
27
+ - `genlayer-js` - Main: client, accounts, transaction decoders, staking utils
28
+ - `genlayer-js/chains` - Chain configs: `localnet`, `studionet`, `testnetAsimov`
29
+ - `genlayer-js/types` - TypeScript types for all SDK entities
30
+
31
+ ### Client Factory Pattern
32
+
33
+ `createClient()` in `src/client/client.ts` builds a composable client by extending viem's base client with action modules:
34
+
35
+ ```
36
+ baseClient → publicActions → walletActions → accountActions
37
+ → transactionActions → chainActions → contractActions
38
+ → receiptActions → stakingActions
39
+ ```
40
+
41
+ Each action module (`src/<domain>/actions.ts`) returns an object of methods that get merged into the client. The client auto-initializes the consensus smart contract on creation.
42
+
43
+ ### Chain Configurations
44
+
45
+ `GenLayerChain` extends viem's `Chain` with GenLayer-specific properties:
46
+ - `isStudio` - Whether using studio-based localnet
47
+ - `consensusMainContract` / `consensusDataContract` - On-chain consensus contracts
48
+ - `stakingContract` - Staking contract (testnet-asimov only)
49
+ - `defaultNumberOfInitialValidators` / `defaultConsensusMaxRotations`
50
+
51
+ ### Calldata Encoding
52
+
53
+ Custom binary encoding for GenLayer transactions in `src/abi/calldata/`:
54
+ - `encoder.ts` - Encodes JS values to GenLayer binary format
55
+ - `decoder.ts` - Decodes binary responses back to JS
56
+ - Uses MessagePack-like format with type tags
57
+
58
+ ### Path Aliases
59
+
60
+ - `@/*` → `./src/*`
61
+ - `@@/tests/*` → `./tests/*`
62
+
63
+ ### Key Dependencies
64
+
65
+ - `viem` - Ethereum client, used as foundation for all blockchain interactions
66
+ - `typescript-parsec` - Parser combinator for calldata string parsing
package/README.md CHANGED
@@ -106,10 +106,61 @@ const receipt = await client.waitForTransactionReceipt({
106
106
  })
107
107
 
108
108
  ```
109
+ ### Staking Operations
110
+
111
+ The SDK provides staking functionality for validators and delegators on testnet-asimov.
112
+
113
+ ```typescript
114
+ import { testnetAsimov } from 'genlayer-js/chains';
115
+ import { createClient, createAccount } from "genlayer-js";
116
+
117
+ const account = createAccount();
118
+ const client = createClient({
119
+ chain: testnetAsimov,
120
+ account,
121
+ });
122
+
123
+ // Get epoch info (includes timing estimates and inflation data)
124
+ const epochInfo = await client.getEpochInfo();
125
+ // {
126
+ // currentEpoch: 2n,
127
+ // epochMinDuration: 86400n, // 1 day in seconds
128
+ // currentEpochStart: Date,
129
+ // currentEpochEnd: Date | null,
130
+ // nextEpochEstimate: Date | null,
131
+ // validatorMinStake: "0.01 GEN",
132
+ // delegatorMinStake: "42 GEN",
133
+ // activeValidatorsCount: 6n,
134
+ // inflation: "1000 GEN", // Total inflation for current epoch
135
+ // inflationRaw: 1000000000000000000000n,
136
+ // totalWeight: 500000000000000000000000n, // Total stake weight
137
+ // totalClaimed: "500 GEN", // Total claimed rewards
138
+ // }
139
+
140
+ // Get active validators
141
+ const validators = await client.getActiveValidators();
142
+
143
+ // Check if address is a validator
144
+ const isValidator = await client.isValidator("0x...");
145
+
146
+ // Get validator info
147
+ const validatorInfo = await client.getValidatorInfo("0x...");
148
+
149
+ // Join as validator (requires account with funds)
150
+ const result = await client.validatorJoin({ amount: "42000gen" });
151
+
152
+ // Join as delegator
153
+ const delegateResult = await client.delegatorJoin({
154
+ validator: "0x...",
155
+ amount: "42gen",
156
+ });
157
+ ```
158
+
109
159
  ## 🚀 Key Features
110
160
 
111
- * **Client Creation**: Easily create and configure a client to connect to GenLayers network.
161
+ * **Client Creation**: Easily create and configure a client to connect to GenLayer's network.
112
162
  * **Transaction Handling**: Send and manage transactions on the GenLayer network.
163
+ * **Staking**: Full staking support for validators and delegators on testnet-asimov.
113
164
  * **Wallet Integration***: Seamless integration with MetaMask for managing user accounts.
114
165
  * **Gas Estimation***: Estimate gas fees for executing transactions on GenLayer.
115
166
 
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkSMGWE7OHcjs = require('../chunk-SMGWE7OH.cjs');
5
+ var _chunkTBF5WZHLcjs = require('../chunk-TBF5WZHL.cjs');
6
6
  require('../chunk-75ZPJI57.cjs');
7
7
 
8
8
 
9
9
 
10
10
 
11
- exports.localnet = _chunkSMGWE7OHcjs.localnet; exports.studionet = _chunkSMGWE7OHcjs.studionet; exports.testnetAsimov = _chunkSMGWE7OHcjs.testnetAsimov;
11
+ exports.localnet = _chunkTBF5WZHLcjs.localnet; exports.studionet = _chunkTBF5WZHLcjs.studionet; exports.testnetAsimov = _chunkTBF5WZHLcjs.testnetAsimov;
@@ -1,3 +1,3 @@
1
- export { l as localnet, s as studionet, t as testnetAsimov } from '../index-C5zeayBB.cjs';
2
- import '../chains-BIe_Q0mF.cjs';
1
+ export { l as localnet, s as studionet, t as testnetAsimov } from '../index-BVDASTaU.cjs';
2
+ import '../chains-B7B7UXdn.cjs';
3
3
  import 'viem';
@@ -1,3 +1,3 @@
1
- export { l as localnet, s as studionet, t as testnetAsimov } from '../index-BpFWfpio.js';
2
- import '../chains-BIe_Q0mF.js';
1
+ export { l as localnet, s as studionet, t as testnetAsimov } from '../index-ucNO2REF.js';
2
+ import '../chains-B7B7UXdn.js';
3
3
  import 'viem';
@@ -2,7 +2,7 @@ import {
2
2
  localnet,
3
3
  studionet,
4
4
  testnetAsimov
5
- } from "../chunk-NO75TOQL.js";
5
+ } from "../chunk-NZI52PRP.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
  export {
8
8
  localnet,
@@ -4,14 +4,18 @@ type GenLayerChain = Chain & {
4
4
  isStudio: boolean;
5
5
  consensusMainContract: {
6
6
  address: Address;
7
- abi: any[];
7
+ abi: readonly unknown[];
8
8
  bytecode: string;
9
9
  } | null;
10
10
  consensusDataContract: {
11
11
  address: Address;
12
- abi: any[];
12
+ abi: readonly unknown[];
13
13
  bytecode: string;
14
14
  } | null;
15
+ stakingContract: {
16
+ address: Address;
17
+ abi: readonly unknown[];
18
+ } | null;
15
19
  defaultNumberOfInitialValidators: number;
16
20
  defaultConsensusMaxRotations: number;
17
21
  };
@@ -4,14 +4,18 @@ type GenLayerChain = Chain & {
4
4
  isStudio: boolean;
5
5
  consensusMainContract: {
6
6
  address: Address;
7
- abi: any[];
7
+ abi: readonly unknown[];
8
8
  bytecode: string;
9
9
  } | null;
10
10
  consensusDataContract: {
11
11
  address: Address;
12
- abi: any[];
12
+ abi: readonly unknown[];
13
13
  bytecode: string;
14
14
  } | null;
15
+ stakingContract: {
16
+ address: Address;
17
+ abi: readonly unknown[];
18
+ } | null;
15
19
  defaultNumberOfInitialValidators: number;
16
20
  defaultConsensusMaxRotations: number;
17
21
  };