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.
- package/CHANGELOG.md +2 -0
- package/CLAUDE.md +66 -0
- package/README.md +52 -1
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.d.cts +2 -2
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/{chains-BIe_Q0mF.d.cts → chains-B7B7UXdn.d.cts} +6 -2
- package/dist/{chains-BIe_Q0mF.d.ts → chains-B7B7UXdn.d.ts} +6 -2
- package/dist/{chunk-NO75TOQL.js → chunk-NZI52PRP.js} +532 -4
- package/dist/{chunk-SMGWE7OH.cjs → chunk-TBF5WZHL.cjs} +533 -5
- package/dist/{index-C5zeayBB.d.cts → index-BVDASTaU.d.cts} +1 -1
- package/dist/index-DPyenUTZ.d.ts +1380 -0
- package/dist/index-Dfaw9WiR.d.cts +1380 -0
- package/dist/{index-BpFWfpio.d.ts → index-ucNO2REF.d.ts} +1 -1
- package/dist/index.cjs +540 -38
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +517 -15
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/src/abi/index.ts +1 -0
- package/src/abi/staking.ts +518 -0
- package/src/chains/localnet.ts +2 -1
- package/src/chains/studionet.ts +1 -0
- package/src/chains/testnetAsimov.ts +10 -3
- package/src/client/client.ts +17 -15
- package/src/index.ts +1 -0
- package/src/staking/actions.ts +598 -0
- package/src/staking/index.ts +2 -0
- package/src/staking/utils.ts +22 -0
- package/src/types/chains.ts +6 -2
- package/src/types/clients.ts +6 -6
- package/src/types/index.ts +1 -0
- package/src/types/staking.ts +228 -0
- package/tsconfig.vitest-temp.json +41 -0
- package/dist/index-B2AY6_eD.d.ts +0 -407
- package/dist/index-BYma5s90.d.cts +0 -407
- /package/dist/{chunk-FPZNF3JH.cjs → chunk-W4V73RPN.cjs} +0 -0
- /package/dist/{chunk-47QDX7IX.js → chunk-ZHBOSLFN.js} +0 -0
package/CHANGELOG.md
CHANGED
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 GenLayer
|
|
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
|
|
package/dist/chains/index.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkTBF5WZHLcjs = require('../chunk-TBF5WZHL.cjs');
|
|
6
6
|
require('../chunk-75ZPJI57.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.localnet =
|
|
11
|
+
exports.localnet = _chunkTBF5WZHLcjs.localnet; exports.studionet = _chunkTBF5WZHLcjs.studionet; exports.testnetAsimov = _chunkTBF5WZHLcjs.testnetAsimov;
|
package/dist/chains/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { l as localnet, s as studionet, t as testnetAsimov } from '../index-
|
|
2
|
-
import '../chains-
|
|
1
|
+
export { l as localnet, s as studionet, t as testnetAsimov } from '../index-BVDASTaU.cjs';
|
|
2
|
+
import '../chains-B7B7UXdn.cjs';
|
|
3
3
|
import 'viem';
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { l as localnet, s as studionet, t as testnetAsimov } from '../index-
|
|
2
|
-
import '../chains-
|
|
1
|
+
export { l as localnet, s as studionet, t as testnetAsimov } from '../index-ucNO2REF.js';
|
|
2
|
+
import '../chains-B7B7UXdn.js';
|
|
3
3
|
import 'viem';
|
package/dist/chains/index.js
CHANGED
|
@@ -4,14 +4,18 @@ type GenLayerChain = Chain & {
|
|
|
4
4
|
isStudio: boolean;
|
|
5
5
|
consensusMainContract: {
|
|
6
6
|
address: Address;
|
|
7
|
-
abi:
|
|
7
|
+
abi: readonly unknown[];
|
|
8
8
|
bytecode: string;
|
|
9
9
|
} | null;
|
|
10
10
|
consensusDataContract: {
|
|
11
11
|
address: Address;
|
|
12
|
-
abi:
|
|
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:
|
|
7
|
+
abi: readonly unknown[];
|
|
8
8
|
bytecode: string;
|
|
9
9
|
} | null;
|
|
10
10
|
consensusDataContract: {
|
|
11
11
|
address: Address;
|
|
12
|
-
abi:
|
|
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
|
};
|