genlayer-js 0.18.4 → 0.18.6
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 +9 -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-KVHGQTAI.js} +539 -4
- package/dist/{chunk-SMGWE7OH.cjs → chunk-QAAO2WJL.cjs} +540 -5
- package/dist/index-3leEwFoq.d.cts +1389 -0
- package/dist/index-BBh1NZjP.d.ts +1389 -0
- package/dist/{index-C5zeayBB.d.cts → index-BVDASTaU.d.cts} +1 -1
- package/dist/{index-BpFWfpio.d.ts → index-ucNO2REF.d.ts} +1 -1
- package/dist/index.cjs +551 -38
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +528 -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 +525 -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 +609 -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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {parseEther, formatEther} from "viem";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse staking amount. Use "gen" suffix for GEN tokens (e.g. "42gen"),
|
|
5
|
+
* otherwise value is treated as wei (e.g. "42000000000000000000" = 42 GEN).
|
|
6
|
+
*/
|
|
7
|
+
export function parseStakingAmount(amount: string | bigint): bigint {
|
|
8
|
+
if (typeof amount === "bigint") return amount;
|
|
9
|
+
const trimmed = amount.trim();
|
|
10
|
+
const lower = trimmed.toLowerCase();
|
|
11
|
+
if (lower.endsWith("gen")) {
|
|
12
|
+
return parseEther(lower.slice(0, -3).trim());
|
|
13
|
+
}
|
|
14
|
+
return BigInt(trimmed);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Format bigint amount to human-readable GEN string.
|
|
19
|
+
*/
|
|
20
|
+
export function formatStakingAmount(amount: bigint): string {
|
|
21
|
+
return `${formatEther(amount)} GEN`;
|
|
22
|
+
}
|
package/src/types/chains.ts
CHANGED
|
@@ -5,14 +5,18 @@ export type GenLayerChain = Chain & {
|
|
|
5
5
|
isStudio: boolean;
|
|
6
6
|
consensusMainContract: {
|
|
7
7
|
address: Address;
|
|
8
|
-
abi:
|
|
8
|
+
abi: readonly unknown[];
|
|
9
9
|
bytecode: string;
|
|
10
10
|
} | null;
|
|
11
11
|
consensusDataContract: {
|
|
12
12
|
address: Address;
|
|
13
|
-
abi:
|
|
13
|
+
abi: readonly unknown[];
|
|
14
14
|
bytecode: string;
|
|
15
15
|
} | null;
|
|
16
|
+
stakingContract: {
|
|
17
|
+
address: Address;
|
|
18
|
+
abi: readonly unknown[];
|
|
19
|
+
} | null;
|
|
16
20
|
defaultNumberOfInitialValidators: number;
|
|
17
21
|
defaultConsensusMaxRotations: number;
|
|
18
22
|
};
|
package/src/types/clients.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {ContractSchema} from "./contracts";
|
|
|
7
7
|
import {Network} from "./network";
|
|
8
8
|
import {SnapSource} from "@/types/snapSource";
|
|
9
9
|
import {MetaMaskClientResult} from "@/types/metamaskClientResult";
|
|
10
|
+
import {StakingActions} from "./staking";
|
|
10
11
|
|
|
11
12
|
export type GenLayerMethod =
|
|
12
13
|
| {method: "sim_fundAccount"; params: [address: Address, amount: number]}
|
|
@@ -22,14 +23,13 @@ export type GenLayerMethod =
|
|
|
22
23
|
| {method: "gen_call"; params: [requestParams: any]};
|
|
23
24
|
|
|
24
25
|
/*
|
|
25
|
-
Take all the properties from
|
|
26
|
-
Remove
|
|
27
|
-
|
|
28
|
-
two properties which are added later
|
|
26
|
+
Take all the properties from Client<Transport, TGenLayerChain>
|
|
27
|
+
Remove getTransaction and readContract because they are redefined with custom implementations.
|
|
28
|
+
Keep transport as it's needed for viem contract interactions (e.g., staking).
|
|
29
29
|
*/
|
|
30
30
|
export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
|
|
31
31
|
Client<Transport, TGenLayerChain>,
|
|
32
|
-
"
|
|
32
|
+
"getTransaction" | "readContract"
|
|
33
33
|
> &
|
|
34
34
|
Omit<WalletActions<TGenLayerChain>, "deployContract" | "writeContract"> &
|
|
35
35
|
Omit<
|
|
@@ -103,4 +103,4 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
|
|
|
103
103
|
account?: Account;
|
|
104
104
|
txId: `0x${string}`;
|
|
105
105
|
}) => Promise<any>;
|
|
106
|
-
};
|
|
106
|
+
} & StakingActions;
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {Address} from "./accounts";
|
|
2
|
+
import {GetContractReturnType, PublicClient, Client, Transport, Chain, Account, Address as ViemAddress} from "viem";
|
|
3
|
+
import {STAKING_ABI} from "@/abi/staking";
|
|
4
|
+
|
|
5
|
+
type WalletClientWithAccount = Client<Transport, Chain, Account>;
|
|
6
|
+
|
|
7
|
+
type StakingKeyedClient = {
|
|
8
|
+
public: PublicClient;
|
|
9
|
+
wallet: WalletClientWithAccount;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type StakingContract = GetContractReturnType<
|
|
13
|
+
typeof STAKING_ABI,
|
|
14
|
+
StakingKeyedClient,
|
|
15
|
+
ViemAddress
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export interface ValidatorView {
|
|
19
|
+
left: Address;
|
|
20
|
+
right: Address;
|
|
21
|
+
parent: Address;
|
|
22
|
+
eBanned: bigint;
|
|
23
|
+
ePrimed: bigint;
|
|
24
|
+
vStake: bigint;
|
|
25
|
+
vShares: bigint;
|
|
26
|
+
dStake: bigint;
|
|
27
|
+
dShares: bigint;
|
|
28
|
+
vDeposit: bigint;
|
|
29
|
+
vWithdrawal: bigint;
|
|
30
|
+
live: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ValidatorIdentity {
|
|
34
|
+
moniker: string;
|
|
35
|
+
logoUri: string;
|
|
36
|
+
website: string;
|
|
37
|
+
description: string;
|
|
38
|
+
email: string;
|
|
39
|
+
twitter: string;
|
|
40
|
+
telegram: string;
|
|
41
|
+
github: string;
|
|
42
|
+
extraCid: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ValidatorInfo {
|
|
46
|
+
address: Address;
|
|
47
|
+
owner: Address;
|
|
48
|
+
operator: Address;
|
|
49
|
+
vStake: string;
|
|
50
|
+
vStakeRaw: bigint;
|
|
51
|
+
vShares: bigint;
|
|
52
|
+
dStake: string;
|
|
53
|
+
dStakeRaw: bigint;
|
|
54
|
+
dShares: bigint;
|
|
55
|
+
vDeposit: string;
|
|
56
|
+
vDepositRaw: bigint;
|
|
57
|
+
vWithdrawal: string;
|
|
58
|
+
vWithdrawalRaw: bigint;
|
|
59
|
+
ePrimed: bigint;
|
|
60
|
+
live: boolean;
|
|
61
|
+
banned: boolean;
|
|
62
|
+
bannedEpoch?: bigint;
|
|
63
|
+
needsPriming: boolean;
|
|
64
|
+
identity?: ValidatorIdentity;
|
|
65
|
+
pendingDeposits: PendingDeposit[];
|
|
66
|
+
pendingWithdrawals: PendingWithdrawal[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface WithdrawalCommit {
|
|
70
|
+
input: bigint;
|
|
71
|
+
output: bigint;
|
|
72
|
+
epoch: bigint;
|
|
73
|
+
linkToNextCommit: bigint;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PendingDeposit {
|
|
77
|
+
epoch: bigint;
|
|
78
|
+
stake: string;
|
|
79
|
+
stakeRaw: bigint;
|
|
80
|
+
shares: bigint;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface PendingWithdrawal {
|
|
84
|
+
epoch: bigint;
|
|
85
|
+
shares: bigint;
|
|
86
|
+
stake: string;
|
|
87
|
+
stakeRaw: bigint;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface BannedValidatorInfo {
|
|
91
|
+
validator: Address;
|
|
92
|
+
untilEpoch: bigint;
|
|
93
|
+
permanentlyBanned: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface StakeInfo {
|
|
97
|
+
delegator: Address;
|
|
98
|
+
validator: Address;
|
|
99
|
+
shares: bigint;
|
|
100
|
+
stake: string;
|
|
101
|
+
stakeRaw: bigint;
|
|
102
|
+
pendingDeposits: PendingDeposit[];
|
|
103
|
+
pendingWithdrawals: PendingWithdrawal[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface EpochData {
|
|
107
|
+
start: bigint;
|
|
108
|
+
end: bigint;
|
|
109
|
+
inflation: bigint;
|
|
110
|
+
weight: bigint;
|
|
111
|
+
weightDeposit: bigint;
|
|
112
|
+
weightWithdrawal: bigint;
|
|
113
|
+
vcount: bigint;
|
|
114
|
+
claimed: bigint;
|
|
115
|
+
stakeDeposit: bigint;
|
|
116
|
+
stakeWithdrawal: bigint;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface EpochInfo {
|
|
120
|
+
currentEpoch: bigint;
|
|
121
|
+
validatorMinStake: string;
|
|
122
|
+
validatorMinStakeRaw: bigint;
|
|
123
|
+
delegatorMinStake: string;
|
|
124
|
+
delegatorMinStakeRaw: bigint;
|
|
125
|
+
activeValidatorsCount: bigint;
|
|
126
|
+
epochMinDuration: bigint;
|
|
127
|
+
currentEpochStart: Date;
|
|
128
|
+
currentEpochEnd: Date | null;
|
|
129
|
+
nextEpochEstimate: Date | null;
|
|
130
|
+
inflation: string;
|
|
131
|
+
inflationRaw: bigint;
|
|
132
|
+
totalWeight: bigint;
|
|
133
|
+
totalClaimed: string;
|
|
134
|
+
totalClaimedRaw: bigint;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface StakingTransactionResult {
|
|
138
|
+
transactionHash: `0x${string}`;
|
|
139
|
+
blockNumber: bigint;
|
|
140
|
+
gasUsed: bigint;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface ValidatorJoinResult extends StakingTransactionResult {
|
|
144
|
+
validatorWallet: Address;
|
|
145
|
+
operator: Address;
|
|
146
|
+
amount: string;
|
|
147
|
+
amountRaw: bigint;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface DelegatorJoinResult extends StakingTransactionResult {
|
|
151
|
+
validator: Address;
|
|
152
|
+
delegator: Address;
|
|
153
|
+
amount: string;
|
|
154
|
+
amountRaw: bigint;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ValidatorJoinOptions {
|
|
158
|
+
amount: bigint | string;
|
|
159
|
+
operator?: Address;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface ValidatorDepositOptions {
|
|
163
|
+
amount: bigint | string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ValidatorExitOptions {
|
|
167
|
+
shares: bigint | string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ValidatorClaimOptions {
|
|
171
|
+
validator?: Address;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface ValidatorPrimeOptions {
|
|
175
|
+
validator: Address;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface SetOperatorOptions {
|
|
179
|
+
validator: Address;
|
|
180
|
+
operator: Address;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface SetIdentityOptions {
|
|
184
|
+
validator: Address;
|
|
185
|
+
moniker: string;
|
|
186
|
+
logoUri?: string;
|
|
187
|
+
website?: string;
|
|
188
|
+
description?: string;
|
|
189
|
+
email?: string;
|
|
190
|
+
twitter?: string;
|
|
191
|
+
telegram?: string;
|
|
192
|
+
github?: string;
|
|
193
|
+
extraCid?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface DelegatorJoinOptions {
|
|
197
|
+
validator: Address;
|
|
198
|
+
amount: bigint | string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface DelegatorExitOptions {
|
|
202
|
+
validator: Address;
|
|
203
|
+
shares: bigint | string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface DelegatorClaimOptions {
|
|
207
|
+
validator: Address;
|
|
208
|
+
delegator?: Address;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface StakingActions {
|
|
212
|
+
validatorJoin: (options: ValidatorJoinOptions) => Promise<ValidatorJoinResult>;
|
|
213
|
+
validatorDeposit: (options: ValidatorDepositOptions) => Promise<StakingTransactionResult>;
|
|
214
|
+
validatorExit: (options: ValidatorExitOptions) => Promise<StakingTransactionResult>;
|
|
215
|
+
validatorClaim: (options?: ValidatorClaimOptions) => Promise<StakingTransactionResult & {claimedAmount: bigint}>;
|
|
216
|
+
delegatorJoin: (options: DelegatorJoinOptions) => Promise<DelegatorJoinResult>;
|
|
217
|
+
delegatorExit: (options: DelegatorExitOptions) => Promise<StakingTransactionResult>;
|
|
218
|
+
delegatorClaim: (options: DelegatorClaimOptions) => Promise<StakingTransactionResult>;
|
|
219
|
+
isValidator: (address: Address) => Promise<boolean>;
|
|
220
|
+
getValidatorInfo: (validator: Address) => Promise<ValidatorInfo>;
|
|
221
|
+
getStakeInfo: (delegator: Address, validator: Address) => Promise<StakeInfo>;
|
|
222
|
+
getEpochInfo: () => Promise<EpochInfo>;
|
|
223
|
+
getActiveValidators: () => Promise<Address[]>;
|
|
224
|
+
getActiveValidatorsCount: () => Promise<bigint>;
|
|
225
|
+
getStakingContract: () => StakingContract;
|
|
226
|
+
parseStakingAmount: (amount: string | bigint) => bigint;
|
|
227
|
+
formatStakingAmount: (amount: bigint) => string;
|
|
228
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"paths": {
|
|
7
|
+
"@/*": [
|
|
8
|
+
"./src/*"
|
|
9
|
+
],
|
|
10
|
+
"@@/tests/*": [
|
|
11
|
+
"./tests/*"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"rootDirs": [
|
|
15
|
+
"./src",
|
|
16
|
+
"./tests"
|
|
17
|
+
],
|
|
18
|
+
"types": [
|
|
19
|
+
"node",
|
|
20
|
+
"jest"
|
|
21
|
+
],
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"sourceMap": true,
|
|
24
|
+
"outDir": "./dist",
|
|
25
|
+
"esModuleInterop": true,
|
|
26
|
+
"forceConsistentCasingInFileNames": true,
|
|
27
|
+
"strict": true,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"emitDeclarationOnly": false,
|
|
30
|
+
"incremental": true,
|
|
31
|
+
"tsBuildInfoFile": "./node_modules/.cache/tsconfig.vitest.tsbuildinfo"
|
|
32
|
+
},
|
|
33
|
+
"include": [
|
|
34
|
+
"src/**/*",
|
|
35
|
+
"tests/**/*",
|
|
36
|
+
"src/global.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"./dist"
|
|
40
|
+
]
|
|
41
|
+
}
|