genlayer-js 0.18.6 → 0.18.8

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.
@@ -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-BBh1NZjP.js';
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-BNui_XYa.js';
3
3
  export { G as GenLayerChain } from '../chains-B7B7UXdn.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.18.6",
4
+ "version": "0.18.8",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -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",
@@ -61,22 +69,115 @@ export const VALIDATOR_WALLET_ABI = [
61
69
  ],
62
70
  outputs: [],
63
71
  },
72
+ // Staking functions (forwarded to staking contract)
73
+ {
74
+ name: "validatorDeposit",
75
+ type: "function",
76
+ stateMutability: "payable",
77
+ inputs: [],
78
+ outputs: [],
79
+ },
80
+ {
81
+ name: "validatorExit",
82
+ type: "function",
83
+ stateMutability: "nonpayable",
84
+ inputs: [{name: "_shares", type: "uint256"}],
85
+ outputs: [],
86
+ },
87
+ {
88
+ name: "validatorClaim",
89
+ type: "function",
90
+ stateMutability: "nonpayable",
91
+ inputs: [],
92
+ outputs: [],
93
+ },
94
+ // Two-step operator transfer
95
+ {
96
+ name: "initiateOperatorTransfer",
97
+ type: "function",
98
+ stateMutability: "nonpayable",
99
+ inputs: [{name: "_newOperator", type: "address"}],
100
+ outputs: [],
101
+ },
102
+ {
103
+ name: "completeOperatorTransfer",
104
+ type: "function",
105
+ stateMutability: "nonpayable",
106
+ inputs: [],
107
+ outputs: [],
108
+ },
109
+ {
110
+ name: "cancelOperatorTransfer",
111
+ type: "function",
112
+ stateMutability: "nonpayable",
113
+ inputs: [],
114
+ outputs: [],
115
+ },
116
+ {
117
+ name: "getPendingOperator",
118
+ type: "function",
119
+ stateMutability: "view",
120
+ inputs: [],
121
+ outputs: [
122
+ {name: "", type: "address"},
123
+ {name: "", type: "uint256"},
124
+ ],
125
+ },
126
+ {
127
+ name: "getOperator",
128
+ type: "function",
129
+ stateMutability: "view",
130
+ inputs: [],
131
+ outputs: [{name: "", type: "address"}],
132
+ },
64
133
  ] as const;
65
134
 
66
135
  export const STAKING_ABI = [
67
- // Custom errors
68
- {name: "BelowMinStake", type: "error", inputs: []},
69
- {name: "AlreadyValidator", type: "error", inputs: []},
70
- {name: "NotValidator", type: "error", inputs: []},
71
- {name: "NotOwner", type: "error", inputs: []},
72
- {name: "NotOperator", type: "error", inputs: []},
73
- {name: "ValidatorBanned", type: "error", inputs: []},
74
- {name: "ValidatorQuarantined", type: "error", inputs: []},
75
- {name: "InsufficientShares", type: "error", inputs: []},
76
- {name: "NothingToClaim", type: "error", inputs: []},
77
- {name: "NotYetClaimable", type: "error", inputs: []},
78
- {name: "ZeroAmount", type: "error", inputs: []},
79
- {name: "InvalidOperator", type: "error", inputs: []},
136
+ // Custom errors from IGenLayerStaking
137
+ {name: "OnlyGEN", type: "error", inputs: []},
138
+ {name: "OnlyTribunal", type: "error", inputs: []},
139
+ {name: "OnlyIdleness", type: "error", inputs: []},
140
+ {name: "OnlyTransactions", type: "error", inputs: []},
141
+ {name: "OnlyIdlenessOrTribunal", type: "error", inputs: []},
142
+ {name: "OnlyTransactionsOrTribunal", type: "error", inputs: []},
143
+ {name: "InvalidAtEpoch", type: "error", inputs: []},
144
+ {name: "MaxValidatorsCannotBeZero", type: "error", inputs: []},
145
+ {name: "ValidatorExitExceedsShares", type: "error", inputs: []},
146
+ {name: "DelegatorExitExceedsShares", type: "error", inputs: []},
147
+ {name: "DelegatorMayNotJoinWithZeroValue", type: "error", inputs: []},
148
+ {name: "DelegatorMayNotJoinTwoValidatorsSimultaneously", type: "error", inputs: []},
149
+ {name: "DelegatorBelowMinimumStake", type: "error", inputs: []},
150
+ {name: "DelegatorExitWouldBeBelowMinimum", type: "error", inputs: []},
151
+ {name: "ValidatorNotActive", type: "error", inputs: []},
152
+ {name: "ValidatorMayNotBeDelegator", type: "error", inputs: []},
153
+ {name: "ValidatorMustNotBeDelegator", type: "error", inputs: []},
154
+ {name: "ValidatorMayNotJoinWithZeroValue", type: "error", inputs: []},
155
+ {name: "ValidatorMayNotDepositZeroValue", type: "error", inputs: []},
156
+ {name: "ValidatorWithdrawalExceedsStake", type: "error", inputs: []},
157
+ {name: "ValidatorAlreadyJoined", type: "error", inputs: []},
158
+ {name: "ValidatorNotJoined", type: "error", inputs: []},
159
+ {name: "ValidatorBelowMinimumStake", type: "error", inputs: []},
160
+ {name: "OperatorAlreadyAssigned", type: "error", inputs: []},
161
+ {name: "InvalidOperatorAddress", type: "error", inputs: []},
162
+ {name: "MaxNumberOfValidatorsReached", type: "error", inputs: []},
163
+ {name: "ValidatorsConsumed", type: "error", inputs: []},
164
+ {name: "ValidatorsUnavailable", type: "error", inputs: []},
165
+ {name: "EpochNotFinished", type: "error", inputs: []},
166
+ {name: "EpochNotFinalized", type: "error", inputs: []},
167
+ {name: "InflationInvalidAmount", type: "error", inputs: []},
168
+ {name: "InflationAlreadyReceived", type: "error", inputs: []},
169
+ {name: "InflationAlreadyInitialized", type: "error", inputs: []},
170
+ {name: "EpochAlreadyFinalized", type: "error", inputs: []},
171
+ {name: "PendingTribunals", type: "error", inputs: [{name: "epoch", type: "uint256"}]},
172
+ {name: "FailedTransfer", type: "error", inputs: [{name: "validator", type: "address"}]},
173
+ {name: "NFTMinterCallFailed", type: "error", inputs: []},
174
+ {name: "DeepthoughtCallFailed", type: "error", inputs: []},
175
+ {name: "NFTMinterNotConfigured", type: "error", inputs: []},
176
+ {name: "NumberOfValidatorsExceedsAvailable", type: "error", inputs: []},
177
+ {name: "EpochAdvanceNotReady", type: "error", inputs: []},
178
+ {name: "PreviousEpochNotFinalizable", type: "error", inputs: []},
179
+ {name: "NoBurning", type: "error", inputs: []},
180
+ {name: "ReductionFactorCannotBeZero", type: "error", inputs: []},
80
181
 
81
182
  // Validator functions
82
183
  {
@@ -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
- return revertError.data?.errorName || revertError.reason || "Unknown reason";
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
  }