genlayer-js 0.18.5 → 0.18.7
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 +14 -0
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/{chunk-TBF5WZHL.cjs → chunk-I23SLL2A.cjs} +59 -13
- package/dist/{chunk-NZI52PRP.js → chunk-RW6PLN5W.js} +59 -13
- package/dist/{index-DPyenUTZ.d.ts → index-9QkkDjYm.d.ts} +175 -12
- package/dist/{index-Dfaw9WiR.d.cts → index-DM646L5c.d.cts} +175 -12
- package/dist/index.cjs +80 -35
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +50 -5
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/abi/staking.ts +60 -13
- package/src/staking/actions.ts +68 -13
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { I as BannedValidatorInfo, d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a3 as DelegatorClaimOptions, a2 as DelegatorExitOptions, a1 as DelegatorJoinOptions, R as DelegatorJoinResult, K as EpochData, L as EpochInfo, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a0 as SetIdentityOptions, $ as SetOperatorOptions, y as SnapSource, J as StakeInfo, a4 as StakingActions, z as StakingContract, O as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, Z as ValidatorClaimOptions, X as ValidatorDepositOptions, Y as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, U as ValidatorJoinOptions, Q as ValidatorJoinResult, _ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { I as BannedValidatorInfo, d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a3 as DelegatorClaimOptions, a2 as DelegatorExitOptions, a1 as DelegatorJoinOptions, R as DelegatorJoinResult, K as EpochData, L as EpochInfo, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a0 as SetIdentityOptions, $ as SetOperatorOptions, y as SnapSource, J as StakeInfo, a4 as StakingActions, z as StakingContract, O as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, Z as ValidatorClaimOptions, X as ValidatorDepositOptions, Y as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, U as ValidatorJoinOptions, Q as ValidatorJoinResult, _ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-DM646L5c.cjs';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-B7B7UXdn.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { I as BannedValidatorInfo, d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a3 as DelegatorClaimOptions, a2 as DelegatorExitOptions, a1 as DelegatorJoinOptions, R as DelegatorJoinResult, K as EpochData, L as EpochInfo, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a0 as SetIdentityOptions, $ as SetOperatorOptions, y as SnapSource, J as StakeInfo, a4 as StakingActions, z as StakingContract, O as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, Z as ValidatorClaimOptions, X as ValidatorDepositOptions, Y as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, U as ValidatorJoinOptions, Q as ValidatorJoinResult, _ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { I as BannedValidatorInfo, d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a3 as DelegatorClaimOptions, a2 as DelegatorExitOptions, a1 as DelegatorJoinOptions, R as DelegatorJoinResult, K as EpochData, L as EpochInfo, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a0 as SetIdentityOptions, $ as SetOperatorOptions, y as SnapSource, J as StakeInfo, a4 as StakingActions, z as StakingContract, O as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, Z as ValidatorClaimOptions, X as ValidatorDepositOptions, Y as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, U as ValidatorJoinOptions, Q as ValidatorJoinResult, _ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-9QkkDjYm.js';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-B7B7UXdn.js';
|
package/package.json
CHANGED
package/src/abi/staking.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
// ValidatorWallet ABI for querying and managing validator wallet
|
|
2
2
|
export const VALIDATOR_WALLET_ABI = [
|
|
3
|
+
// Custom errors
|
|
4
|
+
{name: "NotOperator", type: "error", inputs: []},
|
|
5
|
+
{name: "InvalidAddress", type: "error", inputs: []},
|
|
6
|
+
{name: "TransferFailed", type: "error", inputs: []},
|
|
7
|
+
{name: "OperatorTransferNotReady", type: "error", inputs: []},
|
|
8
|
+
{name: "NoPendingOperator", type: "error", inputs: []},
|
|
9
|
+
|
|
10
|
+
// Functions
|
|
3
11
|
{
|
|
4
12
|
name: "operator",
|
|
5
13
|
type: "function",
|
|
@@ -64,19 +72,51 @@ export const VALIDATOR_WALLET_ABI = [
|
|
|
64
72
|
] as const;
|
|
65
73
|
|
|
66
74
|
export const STAKING_ABI = [
|
|
67
|
-
// Custom errors
|
|
68
|
-
{name: "
|
|
69
|
-
{name: "
|
|
70
|
-
{name: "
|
|
71
|
-
{name: "
|
|
72
|
-
{name: "
|
|
73
|
-
{name: "
|
|
74
|
-
{name: "
|
|
75
|
-
{name: "
|
|
76
|
-
{name: "
|
|
77
|
-
{name: "
|
|
78
|
-
{name: "
|
|
79
|
-
{name: "
|
|
75
|
+
// Custom errors from IGenLayerStaking
|
|
76
|
+
{name: "OnlyGEN", type: "error", inputs: []},
|
|
77
|
+
{name: "OnlyTribunal", type: "error", inputs: []},
|
|
78
|
+
{name: "OnlyIdleness", type: "error", inputs: []},
|
|
79
|
+
{name: "OnlyTransactions", type: "error", inputs: []},
|
|
80
|
+
{name: "OnlyIdlenessOrTribunal", type: "error", inputs: []},
|
|
81
|
+
{name: "OnlyTransactionsOrTribunal", type: "error", inputs: []},
|
|
82
|
+
{name: "InvalidAtEpoch", type: "error", inputs: []},
|
|
83
|
+
{name: "MaxValidatorsCannotBeZero", type: "error", inputs: []},
|
|
84
|
+
{name: "ValidatorExitExceedsShares", type: "error", inputs: []},
|
|
85
|
+
{name: "DelegatorExitExceedsShares", type: "error", inputs: []},
|
|
86
|
+
{name: "DelegatorMayNotJoinWithZeroValue", type: "error", inputs: []},
|
|
87
|
+
{name: "DelegatorMayNotJoinTwoValidatorsSimultaneously", type: "error", inputs: []},
|
|
88
|
+
{name: "DelegatorBelowMinimumStake", type: "error", inputs: []},
|
|
89
|
+
{name: "DelegatorExitWouldBeBelowMinimum", type: "error", inputs: []},
|
|
90
|
+
{name: "ValidatorNotActive", type: "error", inputs: []},
|
|
91
|
+
{name: "ValidatorMayNotBeDelegator", type: "error", inputs: []},
|
|
92
|
+
{name: "ValidatorMustNotBeDelegator", type: "error", inputs: []},
|
|
93
|
+
{name: "ValidatorMayNotJoinWithZeroValue", type: "error", inputs: []},
|
|
94
|
+
{name: "ValidatorMayNotDepositZeroValue", type: "error", inputs: []},
|
|
95
|
+
{name: "ValidatorWithdrawalExceedsStake", type: "error", inputs: []},
|
|
96
|
+
{name: "ValidatorAlreadyJoined", type: "error", inputs: []},
|
|
97
|
+
{name: "ValidatorNotJoined", type: "error", inputs: []},
|
|
98
|
+
{name: "ValidatorBelowMinimumStake", type: "error", inputs: []},
|
|
99
|
+
{name: "OperatorAlreadyAssigned", type: "error", inputs: []},
|
|
100
|
+
{name: "InvalidOperatorAddress", type: "error", inputs: []},
|
|
101
|
+
{name: "MaxNumberOfValidatorsReached", type: "error", inputs: []},
|
|
102
|
+
{name: "ValidatorsConsumed", type: "error", inputs: []},
|
|
103
|
+
{name: "ValidatorsUnavailable", type: "error", inputs: []},
|
|
104
|
+
{name: "EpochNotFinished", type: "error", inputs: []},
|
|
105
|
+
{name: "EpochNotFinalized", type: "error", inputs: []},
|
|
106
|
+
{name: "InflationInvalidAmount", type: "error", inputs: []},
|
|
107
|
+
{name: "InflationAlreadyReceived", type: "error", inputs: []},
|
|
108
|
+
{name: "InflationAlreadyInitialized", type: "error", inputs: []},
|
|
109
|
+
{name: "EpochAlreadyFinalized", type: "error", inputs: []},
|
|
110
|
+
{name: "PendingTribunals", type: "error", inputs: [{name: "epoch", type: "uint256"}]},
|
|
111
|
+
{name: "FailedTransfer", type: "error", inputs: [{name: "validator", type: "address"}]},
|
|
112
|
+
{name: "NFTMinterCallFailed", type: "error", inputs: []},
|
|
113
|
+
{name: "DeepthoughtCallFailed", type: "error", inputs: []},
|
|
114
|
+
{name: "NFTMinterNotConfigured", type: "error", inputs: []},
|
|
115
|
+
{name: "NumberOfValidatorsExceedsAvailable", type: "error", inputs: []},
|
|
116
|
+
{name: "EpochAdvanceNotReady", type: "error", inputs: []},
|
|
117
|
+
{name: "PreviousEpochNotFinalizable", type: "error", inputs: []},
|
|
118
|
+
{name: "NoBurning", type: "error", inputs: []},
|
|
119
|
+
{name: "ReductionFactorCannotBeZero", type: "error", inputs: []},
|
|
80
120
|
|
|
81
121
|
// Validator functions
|
|
82
122
|
{
|
|
@@ -293,6 +333,13 @@ export const STAKING_ABI = [
|
|
|
293
333
|
inputs: [],
|
|
294
334
|
outputs: [{name: "", type: "uint256"}],
|
|
295
335
|
},
|
|
336
|
+
{
|
|
337
|
+
name: "epochZeroMinDuration",
|
|
338
|
+
type: "function",
|
|
339
|
+
stateMutability: "view",
|
|
340
|
+
inputs: [],
|
|
341
|
+
outputs: [{name: "", type: "uint256"}],
|
|
342
|
+
},
|
|
296
343
|
{
|
|
297
344
|
name: "getQuarantinedValidators",
|
|
298
345
|
type: "function",
|
package/src/staking/actions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {getContract, decodeEventLog, PublicClient, Client, Transport, Chain, Account, Address as ViemAddress, GetContractReturnType, toHex, encodeFunctionData, BaseError, ContractFunctionRevertedError} from "viem";
|
|
1
|
+
import {getContract, decodeEventLog, PublicClient, Client, Transport, Chain, Account, Address as ViemAddress, GetContractReturnType, toHex, encodeFunctionData, BaseError, ContractFunctionRevertedError, decodeErrorResult, RawContractError} from "viem";
|
|
2
2
|
import {GenLayerClient, GenLayerChain, Address} from "@/types";
|
|
3
3
|
import {STAKING_ABI, VALIDATOR_WALLET_ABI} from "@/abi/staking";
|
|
4
4
|
import {parseStakingAmount, formatStakingAmount} from "./utils";
|
|
@@ -32,11 +32,55 @@ type WalletClientWithAccount = Client<Transport, Chain, Account>;
|
|
|
32
32
|
const FALLBACK_GAS = 1000000n;
|
|
33
33
|
const GAS_BUFFER_MULTIPLIER = 2n;
|
|
34
34
|
|
|
35
|
+
// Combined ABI for error decoding (both staking and validator wallet errors)
|
|
36
|
+
const COMBINED_ERROR_ABI = [...STAKING_ABI, ...VALIDATOR_WALLET_ABI];
|
|
37
|
+
|
|
35
38
|
function extractRevertReason(err: unknown): string {
|
|
36
39
|
if (err instanceof BaseError) {
|
|
40
|
+
// Try to find raw error data and decode it with our ABI
|
|
41
|
+
const rawError = err.walk((e) => e instanceof RawContractError);
|
|
42
|
+
if (rawError instanceof RawContractError && rawError.data && typeof rawError.data === "string") {
|
|
43
|
+
try {
|
|
44
|
+
const decoded = decodeErrorResult({
|
|
45
|
+
abi: COMBINED_ERROR_ABI,
|
|
46
|
+
data: rawError.data as `0x${string}`,
|
|
47
|
+
});
|
|
48
|
+
return decoded.errorName;
|
|
49
|
+
} catch {
|
|
50
|
+
// Fall through to other methods
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Try to extract error data from the cause chain
|
|
55
|
+
let current: unknown = err;
|
|
56
|
+
while (current) {
|
|
57
|
+
if (current && typeof current === "object") {
|
|
58
|
+
const obj = current as Record<string, unknown>;
|
|
59
|
+
// Check for data property that looks like hex error data
|
|
60
|
+
if (obj.data && typeof obj.data === "string" && obj.data.startsWith("0x")) {
|
|
61
|
+
try {
|
|
62
|
+
const decoded = decodeErrorResult({
|
|
63
|
+
abi: COMBINED_ERROR_ABI,
|
|
64
|
+
data: obj.data as `0x${string}`,
|
|
65
|
+
});
|
|
66
|
+
return decoded.errorName;
|
|
67
|
+
} catch {
|
|
68
|
+
// Continue searching
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
current = obj.cause;
|
|
72
|
+
} else {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
37
77
|
const revertError = err.walk((e) => e instanceof ContractFunctionRevertedError);
|
|
38
78
|
if (revertError instanceof ContractFunctionRevertedError) {
|
|
39
|
-
|
|
79
|
+
// If viem already decoded it, use that
|
|
80
|
+
if (revertError.data?.errorName) {
|
|
81
|
+
return revertError.data.errorName;
|
|
82
|
+
}
|
|
83
|
+
return revertError.reason || "Unknown reason";
|
|
40
84
|
}
|
|
41
85
|
if (err.shortMessage) return err.shortMessage;
|
|
42
86
|
}
|
|
@@ -513,16 +557,25 @@ export const stakingActions = (
|
|
|
513
557
|
getEpochInfo: async (): Promise<EpochInfo> => {
|
|
514
558
|
const contract = getReadOnlyStakingContract();
|
|
515
559
|
|
|
516
|
-
const [
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
560
|
+
const [
|
|
561
|
+
epoch,
|
|
562
|
+
validatorMinStake,
|
|
563
|
+
delegatorMinStake,
|
|
564
|
+
activeCount,
|
|
565
|
+
epochMinDuration,
|
|
566
|
+
epochZeroMinDuration,
|
|
567
|
+
epochOdd,
|
|
568
|
+
epochEven,
|
|
569
|
+
] = await Promise.all([
|
|
570
|
+
contract.read.epoch() as Promise<bigint>,
|
|
571
|
+
contract.read.validatorMinStake() as Promise<bigint>,
|
|
572
|
+
contract.read.delegatorMinStake() as Promise<bigint>,
|
|
573
|
+
contract.read.activeValidatorsCount() as Promise<bigint>,
|
|
574
|
+
contract.read.epochMinDuration() as Promise<bigint>,
|
|
575
|
+
contract.read.epochZeroMinDuration() as Promise<bigint>,
|
|
576
|
+
contract.read.epochOdd() as Promise<any>,
|
|
577
|
+
contract.read.epochEven() as Promise<any>,
|
|
578
|
+
]);
|
|
526
579
|
|
|
527
580
|
// Current epoch data (even epochs use epochEven, odd use epochOdd)
|
|
528
581
|
const currentEpochData = epoch % 2n === 0n ? epochEven : epochOdd;
|
|
@@ -530,9 +583,11 @@ export const stakingActions = (
|
|
|
530
583
|
const currentEpochEnd = currentEpochData.end > 0n ? new Date(Number(currentEpochData.end) * 1000) : null;
|
|
531
584
|
|
|
532
585
|
// Estimate next epoch: current start + min duration (if epoch hasn't ended)
|
|
586
|
+
// Epoch 0 uses epochZeroMinDuration, all other epochs use epochMinDuration
|
|
533
587
|
let nextEpochEstimate: Date | null = null;
|
|
534
588
|
if (!currentEpochEnd) {
|
|
535
|
-
const
|
|
589
|
+
const duration = epoch === 0n ? epochZeroMinDuration : epochMinDuration;
|
|
590
|
+
const estimatedEndMs = Number(currentEpochData.start + duration) * 1000;
|
|
536
591
|
nextEpochEstimate = new Date(estimatedEndMs);
|
|
537
592
|
}
|
|
538
593
|
|