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/dist/index.cjs
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var _chunkSMGWE7OHcjs = require('./chunk-SMGWE7OH.cjs');
|
|
7
6
|
|
|
8
7
|
|
|
8
|
+
var _chunkTBF5WZHLcjs = require('./chunk-TBF5WZHL.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkW4V73RPNcjs = require('./chunk-W4V73RPN.cjs');
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
@@ -29,7 +31,7 @@ var _viem = require('viem');
|
|
|
29
31
|
function accountActions(client) {
|
|
30
32
|
return {
|
|
31
33
|
fundAccount: async ({ address, amount }) => {
|
|
32
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
34
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkTBF5WZHLcjs.localnet.id) {
|
|
33
35
|
throw new Error("Client is not connected to the localnet");
|
|
34
36
|
}
|
|
35
37
|
return client.request({
|
|
@@ -184,7 +186,7 @@ function encodeImpl(to, data) {
|
|
|
184
186
|
}
|
|
185
187
|
} else if (data instanceof Map) {
|
|
186
188
|
encodeMap(to, data);
|
|
187
|
-
} else if (data instanceof
|
|
189
|
+
} else if (data instanceof _chunkW4V73RPNcjs.CalldataAddress) {
|
|
188
190
|
to.push(SPECIAL_ADDR);
|
|
189
191
|
for (const c of data.bytes) {
|
|
190
192
|
to.push(c);
|
|
@@ -259,7 +261,7 @@ function decodeImpl(data, index) {
|
|
|
259
261
|
case BigInt(SPECIAL_ADDR): {
|
|
260
262
|
const res = data.slice(index.i, index.i + 20);
|
|
261
263
|
index.i += 20;
|
|
262
|
-
return new (0,
|
|
264
|
+
return new (0, _chunkW4V73RPNcjs.CalldataAddress)(res);
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
267
|
const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
|
|
@@ -371,7 +373,7 @@ function toStringImpl(data, to) {
|
|
|
371
373
|
to.push("]");
|
|
372
374
|
} else if (data instanceof Map) {
|
|
373
375
|
toStringImplMap(data.entries(), to);
|
|
374
|
-
} else if (data instanceof
|
|
376
|
+
} else if (data instanceof _chunkW4V73RPNcjs.CalldataAddress) {
|
|
375
377
|
to.push("addr#");
|
|
376
378
|
for (const c of data.bytes) {
|
|
377
379
|
to.push(c.toString(16));
|
|
@@ -413,6 +415,8 @@ function serialize(data) {
|
|
|
413
415
|
// src/abi/index.ts
|
|
414
416
|
var abi_exports = {};
|
|
415
417
|
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
418
|
+
STAKING_ABI: () => _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
419
|
+
VALIDATOR_WALLET_ABI: () => _chunkTBF5WZHLcjs.VALIDATOR_WALLET_ABI,
|
|
416
420
|
calldata: () => calldata,
|
|
417
421
|
transactions: () => transactions
|
|
418
422
|
});
|
|
@@ -494,7 +498,7 @@ function _toJsonSafeDeep(value, seen) {
|
|
|
494
498
|
}
|
|
495
499
|
return obj;
|
|
496
500
|
}
|
|
497
|
-
if (value instanceof
|
|
501
|
+
if (value instanceof _chunkW4V73RPNcjs.CalldataAddress) {
|
|
498
502
|
return _viem.toHex.call(void 0, value.bytes);
|
|
499
503
|
}
|
|
500
504
|
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
@@ -512,7 +516,7 @@ function _toJsonSafeDeep(value, seen) {
|
|
|
512
516
|
var contractActions = (client, publicClient) => {
|
|
513
517
|
return {
|
|
514
518
|
getContractCode: async (address) => {
|
|
515
|
-
if (client.chain.id !==
|
|
519
|
+
if (client.chain.id !== _chunkTBF5WZHLcjs.localnet.id) {
|
|
516
520
|
throw new Error("Getting contract code is not supported on this network");
|
|
517
521
|
}
|
|
518
522
|
const result = await client.request({
|
|
@@ -523,7 +527,7 @@ var contractActions = (client, publicClient) => {
|
|
|
523
527
|
return new TextDecoder().decode(codeBytes);
|
|
524
528
|
},
|
|
525
529
|
getContractSchema: async (address) => {
|
|
526
|
-
if (client.chain.id !==
|
|
530
|
+
if (client.chain.id !== _chunkTBF5WZHLcjs.localnet.id) {
|
|
527
531
|
throw new Error("Contract schema is not supported on this network");
|
|
528
532
|
}
|
|
529
533
|
const schema = await client.request({
|
|
@@ -533,7 +537,7 @@ var contractActions = (client, publicClient) => {
|
|
|
533
537
|
return schema;
|
|
534
538
|
},
|
|
535
539
|
getContractSchemaForCode: async (contractCode) => {
|
|
536
|
-
if (client.chain.id !==
|
|
540
|
+
if (client.chain.id !== _chunkTBF5WZHLcjs.localnet.id) {
|
|
537
541
|
throw new Error("Contract schema is not supported on this network");
|
|
538
542
|
}
|
|
539
543
|
const schema = await client.request({
|
|
@@ -681,13 +685,13 @@ var contractActions = (client, publicClient) => {
|
|
|
681
685
|
}
|
|
682
686
|
};
|
|
683
687
|
};
|
|
684
|
-
var validateAccount = (
|
|
685
|
-
if (!
|
|
688
|
+
var validateAccount = (Account4) => {
|
|
689
|
+
if (!Account4) {
|
|
686
690
|
throw new Error(
|
|
687
691
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
688
692
|
);
|
|
689
693
|
}
|
|
690
|
-
return
|
|
694
|
+
return Account4;
|
|
691
695
|
};
|
|
692
696
|
var _encodeAddTransactionData = ({
|
|
693
697
|
client,
|
|
@@ -897,8 +901,8 @@ var decodeTransaction = (tx) => {
|
|
|
897
901
|
processingBlock: tx.readStateBlockRange.processingBlock.toString(),
|
|
898
902
|
proposalBlock: tx.readStateBlockRange.proposalBlock.toString()
|
|
899
903
|
},
|
|
900
|
-
statusName:
|
|
901
|
-
resultName:
|
|
904
|
+
statusName: _chunkW4V73RPNcjs.transactionsStatusNumberToName[String(tx.status)],
|
|
905
|
+
resultName: _chunkW4V73RPNcjs.transactionResultNumberToName[String(tx.result)],
|
|
902
906
|
lastRound: {
|
|
903
907
|
...tx.lastRound,
|
|
904
908
|
round: tx.lastRound.round.toString(),
|
|
@@ -908,7 +912,7 @@ var decodeTransaction = (tx) => {
|
|
|
908
912
|
appealBond: tx.lastRound.appealBond.toString(),
|
|
909
913
|
rotationsLeft: tx.lastRound.rotationsLeft.toString(),
|
|
910
914
|
validatorVotesName: tx.lastRound.validatorVotes.map(
|
|
911
|
-
(vote) =>
|
|
915
|
+
(vote) => _chunkW4V73RPNcjs.voteTypeNumberToName[String(vote)]
|
|
912
916
|
)
|
|
913
917
|
}
|
|
914
918
|
};
|
|
@@ -1047,10 +1051,10 @@ var receiptActions = (client, publicClient) => ({
|
|
|
1047
1051
|
throw new Error("Transaction not found");
|
|
1048
1052
|
}
|
|
1049
1053
|
const transactionStatusString = String(transaction.status);
|
|
1050
|
-
const requestedStatus =
|
|
1051
|
-
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ &&
|
|
1054
|
+
const requestedStatus = _chunkW4V73RPNcjs.transactionsStatusNameToNumber[status];
|
|
1055
|
+
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && _chunkW4V73RPNcjs.isDecidedState.call(void 0, transactionStatusString)) {
|
|
1052
1056
|
let finalTransaction = transaction;
|
|
1053
|
-
if (client.chain.id ===
|
|
1057
|
+
if (client.chain.id === _chunkTBF5WZHLcjs.localnet.id) {
|
|
1054
1058
|
finalTransaction = decodeLocalnetTransaction(transaction);
|
|
1055
1059
|
}
|
|
1056
1060
|
if (!fullTransaction) {
|
|
@@ -1076,7 +1080,7 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1076
1080
|
if (client.chain.isStudio) {
|
|
1077
1081
|
const transaction2 = await client.getTransaction({ hash });
|
|
1078
1082
|
const localnetStatus = transaction2.status === "ACTIVATED" ? "PENDING" /* PENDING */ : transaction2.status;
|
|
1079
|
-
transaction2.status = Number(
|
|
1083
|
+
transaction2.status = Number(_chunkW4V73RPNcjs.transactionsStatusNameToNumber[localnetStatus]);
|
|
1080
1084
|
transaction2.statusName = localnetStatus;
|
|
1081
1085
|
return decodeLocalnetTransaction(transaction2);
|
|
1082
1086
|
}
|
|
@@ -1115,9 +1119,9 @@ var snapID = {
|
|
|
1115
1119
|
|
|
1116
1120
|
// src/wallet/connect.ts
|
|
1117
1121
|
var networks = {
|
|
1118
|
-
localnet:
|
|
1119
|
-
studionet:
|
|
1120
|
-
testnetAsimov:
|
|
1122
|
+
localnet: _chunkTBF5WZHLcjs.localnet,
|
|
1123
|
+
studionet: _chunkTBF5WZHLcjs.studionet,
|
|
1124
|
+
testnetAsimov: _chunkTBF5WZHLcjs.testnetAsimov
|
|
1121
1125
|
};
|
|
1122
1126
|
var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
1123
1127
|
if (!window.ethereum) {
|
|
@@ -1212,14 +1216,506 @@ function walletActions(client) {
|
|
|
1212
1216
|
};
|
|
1213
1217
|
}
|
|
1214
1218
|
|
|
1219
|
+
// src/staking/actions.ts
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
// src/staking/utils.ts
|
|
1223
|
+
|
|
1224
|
+
function parseStakingAmount(amount) {
|
|
1225
|
+
if (typeof amount === "bigint") return amount;
|
|
1226
|
+
const trimmed = amount.trim();
|
|
1227
|
+
const lower = trimmed.toLowerCase();
|
|
1228
|
+
if (lower.endsWith("gen")) {
|
|
1229
|
+
return _viem.parseEther.call(void 0, lower.slice(0, -3).trim());
|
|
1230
|
+
}
|
|
1231
|
+
return BigInt(trimmed);
|
|
1232
|
+
}
|
|
1233
|
+
function formatStakingAmount(amount) {
|
|
1234
|
+
return `${_viem.formatEther.call(void 0, amount)} GEN`;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// src/staking/actions.ts
|
|
1238
|
+
var FALLBACK_GAS = 1000000n;
|
|
1239
|
+
var GAS_BUFFER_MULTIPLIER = 2n;
|
|
1240
|
+
function extractRevertReason(err) {
|
|
1241
|
+
if (err instanceof _viem.BaseError) {
|
|
1242
|
+
const revertError = err.walk((e) => e instanceof _viem.ContractFunctionRevertedError);
|
|
1243
|
+
if (revertError instanceof _viem.ContractFunctionRevertedError) {
|
|
1244
|
+
return _optionalChain([revertError, 'access', _54 => _54.data, 'optionalAccess', _55 => _55.errorName]) || revertError.reason || "Unknown reason";
|
|
1245
|
+
}
|
|
1246
|
+
if (err.shortMessage) return err.shortMessage;
|
|
1247
|
+
}
|
|
1248
|
+
if (err instanceof Error) return err.message;
|
|
1249
|
+
return "Unknown reason";
|
|
1250
|
+
}
|
|
1251
|
+
var stakingActions = (client, publicClient) => {
|
|
1252
|
+
const executeWrite = async (options) => {
|
|
1253
|
+
if (!client.account) {
|
|
1254
|
+
throw new Error("Account is required for write operations. Initialize client with a wallet account.");
|
|
1255
|
+
}
|
|
1256
|
+
const account = client.account;
|
|
1257
|
+
try {
|
|
1258
|
+
await publicClient.call({
|
|
1259
|
+
account,
|
|
1260
|
+
to: options.to,
|
|
1261
|
+
data: options.data,
|
|
1262
|
+
value: options.value
|
|
1263
|
+
});
|
|
1264
|
+
} catch (err) {
|
|
1265
|
+
const revertReason = extractRevertReason(err);
|
|
1266
|
+
throw new Error(`Transaction would revert: ${revertReason}`);
|
|
1267
|
+
}
|
|
1268
|
+
let gasLimit = options.gas;
|
|
1269
|
+
if (!gasLimit) {
|
|
1270
|
+
try {
|
|
1271
|
+
const estimated = await publicClient.estimateGas({
|
|
1272
|
+
account,
|
|
1273
|
+
to: options.to,
|
|
1274
|
+
data: options.data,
|
|
1275
|
+
value: options.value
|
|
1276
|
+
});
|
|
1277
|
+
gasLimit = estimated * GAS_BUFFER_MULTIPLIER;
|
|
1278
|
+
} catch (e2) {
|
|
1279
|
+
gasLimit = FALLBACK_GAS;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
const nonce = await publicClient.getTransactionCount({ address: account.address });
|
|
1283
|
+
const txRequest = await publicClient.prepareTransactionRequest({
|
|
1284
|
+
account,
|
|
1285
|
+
to: options.to,
|
|
1286
|
+
data: options.data,
|
|
1287
|
+
value: options.value,
|
|
1288
|
+
type: "legacy",
|
|
1289
|
+
nonce,
|
|
1290
|
+
gas: gasLimit,
|
|
1291
|
+
chain: client.chain
|
|
1292
|
+
});
|
|
1293
|
+
const signTransaction = account.signTransaction;
|
|
1294
|
+
if (!signTransaction) {
|
|
1295
|
+
throw new Error("Account does not support signing transactions");
|
|
1296
|
+
}
|
|
1297
|
+
const serializedTx = await signTransaction(txRequest);
|
|
1298
|
+
const hash = await publicClient.sendRawTransaction({ serializedTransaction: serializedTx });
|
|
1299
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
1300
|
+
if (receipt.status === "reverted") {
|
|
1301
|
+
let revertReason = "Unknown reason";
|
|
1302
|
+
try {
|
|
1303
|
+
await publicClient.call({
|
|
1304
|
+
account,
|
|
1305
|
+
to: options.to,
|
|
1306
|
+
data: options.data,
|
|
1307
|
+
value: options.value,
|
|
1308
|
+
blockNumber: receipt.blockNumber
|
|
1309
|
+
});
|
|
1310
|
+
const gasUsed = receipt.gasUsed;
|
|
1311
|
+
if (gasUsed >= gasLimit - 1000n) {
|
|
1312
|
+
revertReason = `Out of gas (used ${gasUsed}, limit ${gasLimit})`;
|
|
1313
|
+
} else {
|
|
1314
|
+
revertReason = `Unknown (simulation passes but tx reverts). Gas: ${gasUsed}/${gasLimit}`;
|
|
1315
|
+
}
|
|
1316
|
+
} catch (err) {
|
|
1317
|
+
revertReason = extractRevertReason(err);
|
|
1318
|
+
}
|
|
1319
|
+
throw new Error(`Transaction reverted: ${revertReason} (tx: ${hash})`);
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
transactionHash: receipt.transactionHash,
|
|
1323
|
+
blockNumber: receipt.blockNumber,
|
|
1324
|
+
gasUsed: receipt.gasUsed
|
|
1325
|
+
};
|
|
1326
|
+
};
|
|
1327
|
+
const getStakingAddress = () => {
|
|
1328
|
+
const stakingConfig = client.chain.stakingContract;
|
|
1329
|
+
if (!_optionalChain([stakingConfig, 'optionalAccess', _56 => _56.address]) || stakingConfig.address === "0x0000000000000000000000000000000000000000") {
|
|
1330
|
+
throw new Error("Staking is not supported on studio-based networks. Use testnet-asimov for staking operations.");
|
|
1331
|
+
}
|
|
1332
|
+
return stakingConfig.address;
|
|
1333
|
+
};
|
|
1334
|
+
const getStakingContract = () => {
|
|
1335
|
+
const address = getStakingAddress();
|
|
1336
|
+
return _viem.getContract.call(void 0, {
|
|
1337
|
+
address,
|
|
1338
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1339
|
+
client: { public: publicClient, wallet: client }
|
|
1340
|
+
});
|
|
1341
|
+
};
|
|
1342
|
+
const getReadOnlyStakingContract = () => {
|
|
1343
|
+
const address = getStakingAddress();
|
|
1344
|
+
return _viem.getContract.call(void 0, {
|
|
1345
|
+
address,
|
|
1346
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1347
|
+
client: publicClient
|
|
1348
|
+
});
|
|
1349
|
+
};
|
|
1350
|
+
return {
|
|
1351
|
+
validatorJoin: async (options) => {
|
|
1352
|
+
const amount = parseStakingAmount(options.amount);
|
|
1353
|
+
const stakingAddress = getStakingAddress();
|
|
1354
|
+
const data = options.operator ? _viem.encodeFunctionData.call(void 0, {
|
|
1355
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1356
|
+
functionName: "validatorJoin",
|
|
1357
|
+
args: [options.operator]
|
|
1358
|
+
}) : _viem.encodeFunctionData.call(void 0, {
|
|
1359
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1360
|
+
functionName: "validatorJoin"
|
|
1361
|
+
});
|
|
1362
|
+
const result = await executeWrite({ to: stakingAddress, data, value: amount });
|
|
1363
|
+
const receipt = await publicClient.getTransactionReceipt({ hash: result.transactionHash });
|
|
1364
|
+
let validatorWallet;
|
|
1365
|
+
let eventFound = false;
|
|
1366
|
+
for (const log of receipt.logs) {
|
|
1367
|
+
try {
|
|
1368
|
+
const decoded = _viem.decodeEventLog.call(void 0, { abi: _chunkTBF5WZHLcjs.STAKING_ABI, data: log.data, topics: log.topics });
|
|
1369
|
+
if (decoded.eventName === "ValidatorJoin") {
|
|
1370
|
+
validatorWallet = decoded.args.validator;
|
|
1371
|
+
eventFound = true;
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
} catch (e3) {
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
if (!eventFound) {
|
|
1378
|
+
throw new Error(
|
|
1379
|
+
`ValidatorJoin event not found in transaction ${result.transactionHash}. Transaction succeeded but validator wallet address could not be determined.`
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
return {
|
|
1383
|
+
transactionHash: receipt.transactionHash,
|
|
1384
|
+
blockNumber: receipt.blockNumber,
|
|
1385
|
+
gasUsed: receipt.gasUsed,
|
|
1386
|
+
validatorWallet,
|
|
1387
|
+
operator: options.operator || client.account.address,
|
|
1388
|
+
amount: formatStakingAmount(amount),
|
|
1389
|
+
amountRaw: amount
|
|
1390
|
+
};
|
|
1391
|
+
},
|
|
1392
|
+
validatorDeposit: async (options) => {
|
|
1393
|
+
const amount = parseStakingAmount(options.amount);
|
|
1394
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1395
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1396
|
+
functionName: "validatorDeposit"
|
|
1397
|
+
});
|
|
1398
|
+
return executeWrite({ to: getStakingAddress(), data, value: amount });
|
|
1399
|
+
},
|
|
1400
|
+
validatorExit: async (options) => {
|
|
1401
|
+
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1402
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1403
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1404
|
+
functionName: "validatorExit",
|
|
1405
|
+
args: [shares]
|
|
1406
|
+
});
|
|
1407
|
+
return executeWrite({ to: getStakingAddress(), data });
|
|
1408
|
+
},
|
|
1409
|
+
validatorClaim: async (options) => {
|
|
1410
|
+
if (!_optionalChain([options, 'optionalAccess', _57 => _57.validator]) && !client.account) {
|
|
1411
|
+
throw new Error("Either provide validator address or initialize client with an account");
|
|
1412
|
+
}
|
|
1413
|
+
const validatorAddress = _optionalChain([options, 'optionalAccess', _58 => _58.validator]) || client.account.address;
|
|
1414
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1415
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1416
|
+
functionName: "validatorClaim",
|
|
1417
|
+
args: [validatorAddress]
|
|
1418
|
+
});
|
|
1419
|
+
const result = await executeWrite({ to: getStakingAddress(), data });
|
|
1420
|
+
return { ...result, claimedAmount: 0n };
|
|
1421
|
+
},
|
|
1422
|
+
validatorPrime: async (options) => {
|
|
1423
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1424
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1425
|
+
functionName: "validatorPrime",
|
|
1426
|
+
args: [options.validator]
|
|
1427
|
+
});
|
|
1428
|
+
return executeWrite({ to: getStakingAddress(), data });
|
|
1429
|
+
},
|
|
1430
|
+
setOperator: async (options) => {
|
|
1431
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1432
|
+
abi: _chunkTBF5WZHLcjs.VALIDATOR_WALLET_ABI,
|
|
1433
|
+
functionName: "setOperator",
|
|
1434
|
+
args: [options.operator]
|
|
1435
|
+
});
|
|
1436
|
+
return executeWrite({ to: options.validator, data });
|
|
1437
|
+
},
|
|
1438
|
+
setIdentity: async (options) => {
|
|
1439
|
+
let extraCidBytes = "0x";
|
|
1440
|
+
if (options.extraCid) {
|
|
1441
|
+
if (options.extraCid.startsWith("0x")) {
|
|
1442
|
+
extraCidBytes = options.extraCid;
|
|
1443
|
+
} else {
|
|
1444
|
+
extraCidBytes = _viem.toHex.call(void 0, new TextEncoder().encode(options.extraCid));
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1448
|
+
abi: _chunkTBF5WZHLcjs.VALIDATOR_WALLET_ABI,
|
|
1449
|
+
functionName: "setIdentity",
|
|
1450
|
+
args: [
|
|
1451
|
+
options.moniker,
|
|
1452
|
+
options.logoUri || "",
|
|
1453
|
+
options.website || "",
|
|
1454
|
+
options.description || "",
|
|
1455
|
+
options.email || "",
|
|
1456
|
+
options.twitter || "",
|
|
1457
|
+
options.telegram || "",
|
|
1458
|
+
options.github || "",
|
|
1459
|
+
extraCidBytes
|
|
1460
|
+
]
|
|
1461
|
+
});
|
|
1462
|
+
return executeWrite({ to: options.validator, data });
|
|
1463
|
+
},
|
|
1464
|
+
delegatorJoin: async (options) => {
|
|
1465
|
+
const amount = parseStakingAmount(options.amount);
|
|
1466
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1467
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1468
|
+
functionName: "delegatorJoin",
|
|
1469
|
+
args: [options.validator]
|
|
1470
|
+
});
|
|
1471
|
+
const result = await executeWrite({ to: getStakingAddress(), data, value: amount });
|
|
1472
|
+
return {
|
|
1473
|
+
...result,
|
|
1474
|
+
validator: options.validator,
|
|
1475
|
+
delegator: client.account.address,
|
|
1476
|
+
amount: formatStakingAmount(amount),
|
|
1477
|
+
amountRaw: amount
|
|
1478
|
+
};
|
|
1479
|
+
},
|
|
1480
|
+
delegatorExit: async (options) => {
|
|
1481
|
+
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1482
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1483
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1484
|
+
functionName: "delegatorExit",
|
|
1485
|
+
args: [options.validator, shares]
|
|
1486
|
+
});
|
|
1487
|
+
return executeWrite({ to: getStakingAddress(), data });
|
|
1488
|
+
},
|
|
1489
|
+
delegatorClaim: async (options) => {
|
|
1490
|
+
if (!options.delegator && !client.account) {
|
|
1491
|
+
throw new Error("Either provide delegator address or initialize client with an account");
|
|
1492
|
+
}
|
|
1493
|
+
const delegatorAddress = options.delegator || client.account.address;
|
|
1494
|
+
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1495
|
+
abi: _chunkTBF5WZHLcjs.STAKING_ABI,
|
|
1496
|
+
functionName: "delegatorClaim",
|
|
1497
|
+
args: [delegatorAddress, options.validator]
|
|
1498
|
+
});
|
|
1499
|
+
return executeWrite({ to: getStakingAddress(), data });
|
|
1500
|
+
},
|
|
1501
|
+
isValidator: async (address) => {
|
|
1502
|
+
const contract = getReadOnlyStakingContract();
|
|
1503
|
+
return contract.read.isValidator([address]);
|
|
1504
|
+
},
|
|
1505
|
+
getValidatorInfo: async (validator) => {
|
|
1506
|
+
const contract = getReadOnlyStakingContract();
|
|
1507
|
+
const isVal = await contract.read.isValidator([validator]);
|
|
1508
|
+
if (!isVal) {
|
|
1509
|
+
throw new Error(`Address ${validator} is not a validator`);
|
|
1510
|
+
}
|
|
1511
|
+
const walletContract = _viem.getContract.call(void 0, {
|
|
1512
|
+
address: validator,
|
|
1513
|
+
abi: _chunkTBF5WZHLcjs.VALIDATOR_WALLET_ABI,
|
|
1514
|
+
client: publicClient
|
|
1515
|
+
});
|
|
1516
|
+
const [view, owner, operator, identityRaw, currentEpoch] = await Promise.all([
|
|
1517
|
+
contract.read.validatorView([validator]),
|
|
1518
|
+
walletContract.read.owner(),
|
|
1519
|
+
walletContract.read.operator(),
|
|
1520
|
+
walletContract.read.getIdentity().catch(() => null),
|
|
1521
|
+
contract.read.epoch()
|
|
1522
|
+
]);
|
|
1523
|
+
let identity;
|
|
1524
|
+
if (identityRaw && identityRaw.moniker) {
|
|
1525
|
+
identity = {
|
|
1526
|
+
moniker: identityRaw.moniker,
|
|
1527
|
+
logoUri: identityRaw.logoUri,
|
|
1528
|
+
website: identityRaw.website,
|
|
1529
|
+
description: identityRaw.description,
|
|
1530
|
+
email: identityRaw.email,
|
|
1531
|
+
twitter: identityRaw.twitter,
|
|
1532
|
+
telegram: identityRaw.telegram,
|
|
1533
|
+
github: identityRaw.github,
|
|
1534
|
+
extraCid: identityRaw.extraCid ? _viem.toHex.call(void 0, identityRaw.extraCid) : ""
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
const needsPriming = currentEpoch > 0n && view.ePrimed < currentEpoch - 1n;
|
|
1538
|
+
const depositLen = await contract.read.validatorDepositLen([validator]);
|
|
1539
|
+
const pendingDeposits = [];
|
|
1540
|
+
for (let i = 0n; i < depositLen; i++) {
|
|
1541
|
+
const [epoch, commit] = await contract.read.validatorDeposit([validator, i]);
|
|
1542
|
+
pendingDeposits.push({
|
|
1543
|
+
epoch,
|
|
1544
|
+
stake: formatStakingAmount(commit.input),
|
|
1545
|
+
stakeRaw: commit.input,
|
|
1546
|
+
shares: commit.output
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
const withdrawalLen = await contract.read.validatorWithdrawalLen([validator]);
|
|
1550
|
+
const pendingWithdrawals = [];
|
|
1551
|
+
for (let i = 0n; i < withdrawalLen; i++) {
|
|
1552
|
+
const [epoch, commit] = await contract.read.validatorWithdrawal([validator, i]);
|
|
1553
|
+
pendingWithdrawals.push({
|
|
1554
|
+
epoch,
|
|
1555
|
+
shares: commit.input,
|
|
1556
|
+
stake: formatStakingAmount(commit.output),
|
|
1557
|
+
stakeRaw: commit.output
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
return {
|
|
1561
|
+
address: validator,
|
|
1562
|
+
owner,
|
|
1563
|
+
operator,
|
|
1564
|
+
vStake: formatStakingAmount(view.vStake),
|
|
1565
|
+
vStakeRaw: view.vStake,
|
|
1566
|
+
vShares: view.vShares,
|
|
1567
|
+
dStake: formatStakingAmount(view.dStake),
|
|
1568
|
+
dStakeRaw: view.dStake,
|
|
1569
|
+
dShares: view.dShares,
|
|
1570
|
+
vDeposit: formatStakingAmount(view.vDeposit),
|
|
1571
|
+
vDepositRaw: view.vDeposit,
|
|
1572
|
+
vWithdrawal: formatStakingAmount(view.vWithdrawal),
|
|
1573
|
+
vWithdrawalRaw: view.vWithdrawal,
|
|
1574
|
+
ePrimed: view.ePrimed,
|
|
1575
|
+
live: view.live,
|
|
1576
|
+
banned: view.eBanned > 0n,
|
|
1577
|
+
bannedEpoch: view.eBanned > 0n ? view.eBanned : void 0,
|
|
1578
|
+
needsPriming,
|
|
1579
|
+
identity,
|
|
1580
|
+
pendingDeposits,
|
|
1581
|
+
pendingWithdrawals
|
|
1582
|
+
};
|
|
1583
|
+
},
|
|
1584
|
+
getStakeInfo: async (delegator, validator) => {
|
|
1585
|
+
const contract = getReadOnlyStakingContract();
|
|
1586
|
+
const shares = await contract.read.sharesOf([delegator, validator]);
|
|
1587
|
+
let stake = 0n;
|
|
1588
|
+
if (shares > 0n) {
|
|
1589
|
+
stake = await contract.read.stakeOf([delegator, validator]);
|
|
1590
|
+
}
|
|
1591
|
+
const depositLen = await contract.read.delegatorDepositLen([
|
|
1592
|
+
delegator,
|
|
1593
|
+
validator
|
|
1594
|
+
]);
|
|
1595
|
+
const pendingDeposits = [];
|
|
1596
|
+
for (let i = 0n; i < depositLen; i++) {
|
|
1597
|
+
const [claim, commit] = await contract.read.delegatorDeposit([
|
|
1598
|
+
delegator,
|
|
1599
|
+
validator,
|
|
1600
|
+
i
|
|
1601
|
+
]);
|
|
1602
|
+
pendingDeposits.push({
|
|
1603
|
+
epoch: commit.epoch,
|
|
1604
|
+
stake: formatStakingAmount(commit.input),
|
|
1605
|
+
stakeRaw: commit.input,
|
|
1606
|
+
shares: claim.quantity
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
const withdrawalLen = await contract.read.delegatorWithdrawalLen([
|
|
1610
|
+
delegator,
|
|
1611
|
+
validator
|
|
1612
|
+
]);
|
|
1613
|
+
const pendingWithdrawals = [];
|
|
1614
|
+
for (let i = 0n; i < withdrawalLen; i++) {
|
|
1615
|
+
const [claim, commit] = await contract.read.delegatorWithdrawal([
|
|
1616
|
+
delegator,
|
|
1617
|
+
validator,
|
|
1618
|
+
i
|
|
1619
|
+
]);
|
|
1620
|
+
pendingWithdrawals.push({
|
|
1621
|
+
epoch: commit.epoch,
|
|
1622
|
+
shares: claim.quantity,
|
|
1623
|
+
stake: formatStakingAmount(commit.output),
|
|
1624
|
+
stakeRaw: commit.output
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
return {
|
|
1628
|
+
delegator,
|
|
1629
|
+
validator,
|
|
1630
|
+
shares,
|
|
1631
|
+
stake: formatStakingAmount(stake),
|
|
1632
|
+
stakeRaw: stake,
|
|
1633
|
+
pendingDeposits,
|
|
1634
|
+
pendingWithdrawals
|
|
1635
|
+
};
|
|
1636
|
+
},
|
|
1637
|
+
getEpochInfo: async () => {
|
|
1638
|
+
const contract = getReadOnlyStakingContract();
|
|
1639
|
+
const [epoch, validatorMinStake, delegatorMinStake, activeCount, epochMinDuration, epochOdd, epochEven] = await Promise.all([
|
|
1640
|
+
contract.read.epoch(),
|
|
1641
|
+
contract.read.validatorMinStake(),
|
|
1642
|
+
contract.read.delegatorMinStake(),
|
|
1643
|
+
contract.read.activeValidatorsCount(),
|
|
1644
|
+
contract.read.epochMinDuration(),
|
|
1645
|
+
contract.read.epochOdd(),
|
|
1646
|
+
contract.read.epochEven()
|
|
1647
|
+
]);
|
|
1648
|
+
const currentEpochData = epoch % 2n === 0n ? epochEven : epochOdd;
|
|
1649
|
+
const currentEpochStart = new Date(Number(currentEpochData.start) * 1e3);
|
|
1650
|
+
const currentEpochEnd = currentEpochData.end > 0n ? new Date(Number(currentEpochData.end) * 1e3) : null;
|
|
1651
|
+
let nextEpochEstimate = null;
|
|
1652
|
+
if (!currentEpochEnd) {
|
|
1653
|
+
const estimatedEndMs = Number(currentEpochData.start + epochMinDuration) * 1e3;
|
|
1654
|
+
nextEpochEstimate = new Date(estimatedEndMs);
|
|
1655
|
+
}
|
|
1656
|
+
return {
|
|
1657
|
+
currentEpoch: epoch,
|
|
1658
|
+
validatorMinStake: formatStakingAmount(validatorMinStake),
|
|
1659
|
+
validatorMinStakeRaw: validatorMinStake,
|
|
1660
|
+
delegatorMinStake: formatStakingAmount(delegatorMinStake),
|
|
1661
|
+
delegatorMinStakeRaw: delegatorMinStake,
|
|
1662
|
+
activeValidatorsCount: activeCount,
|
|
1663
|
+
epochMinDuration,
|
|
1664
|
+
currentEpochStart,
|
|
1665
|
+
currentEpochEnd,
|
|
1666
|
+
nextEpochEstimate,
|
|
1667
|
+
inflation: formatStakingAmount(currentEpochData.inflation),
|
|
1668
|
+
inflationRaw: currentEpochData.inflation,
|
|
1669
|
+
totalWeight: currentEpochData.weight,
|
|
1670
|
+
totalClaimed: formatStakingAmount(currentEpochData.claimed),
|
|
1671
|
+
totalClaimedRaw: currentEpochData.claimed
|
|
1672
|
+
};
|
|
1673
|
+
},
|
|
1674
|
+
getActiveValidators: async () => {
|
|
1675
|
+
const contract = getReadOnlyStakingContract();
|
|
1676
|
+
const validators = await contract.read.activeValidators();
|
|
1677
|
+
return validators.filter((v) => v !== "0x0000000000000000000000000000000000000000");
|
|
1678
|
+
},
|
|
1679
|
+
getActiveValidatorsCount: async () => {
|
|
1680
|
+
const contract = getReadOnlyStakingContract();
|
|
1681
|
+
return contract.read.activeValidatorsCount();
|
|
1682
|
+
},
|
|
1683
|
+
getQuarantinedValidators: async () => {
|
|
1684
|
+
const contract = getReadOnlyStakingContract();
|
|
1685
|
+
return contract.read.getQuarantinedValidators();
|
|
1686
|
+
},
|
|
1687
|
+
getBannedValidators: async (startIndex = 0n, size = 100n) => {
|
|
1688
|
+
const contract = getReadOnlyStakingContract();
|
|
1689
|
+
const result = await contract.read.getAllBannedValidators([startIndex, size]);
|
|
1690
|
+
return result.map((v) => ({
|
|
1691
|
+
validator: v.validator,
|
|
1692
|
+
untilEpoch: v.untilEpochBanned,
|
|
1693
|
+
permanentlyBanned: v.permanentlyBanned
|
|
1694
|
+
}));
|
|
1695
|
+
},
|
|
1696
|
+
getQuarantinedValidatorsDetailed: async (startIndex = 0n, size = 100n) => {
|
|
1697
|
+
const contract = getReadOnlyStakingContract();
|
|
1698
|
+
const result = await contract.read.getAllQuarantinedValidators([startIndex, size]);
|
|
1699
|
+
return result.map((v) => ({
|
|
1700
|
+
validator: v.validator,
|
|
1701
|
+
untilEpoch: v.untilEpochBanned,
|
|
1702
|
+
permanentlyBanned: v.permanentlyBanned
|
|
1703
|
+
}));
|
|
1704
|
+
},
|
|
1705
|
+
getStakingContract,
|
|
1706
|
+
parseStakingAmount,
|
|
1707
|
+
formatStakingAmount
|
|
1708
|
+
};
|
|
1709
|
+
};
|
|
1710
|
+
|
|
1215
1711
|
// src/chains/actions.ts
|
|
1216
1712
|
function chainActions(client) {
|
|
1217
1713
|
return {
|
|
1218
1714
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
1219
|
-
if (_optionalChain([client, 'access',
|
|
1715
|
+
if (_optionalChain([client, 'access', _59 => _59.chain, 'optionalAccess', _60 => _60.id]) === _chunkTBF5WZHLcjs.testnetAsimov.id) {
|
|
1220
1716
|
return;
|
|
1221
1717
|
}
|
|
1222
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
1718
|
+
if (!forceReset && _optionalChain([client, 'access', _61 => _61.chain, 'access', _62 => _62.consensusMainContract, 'optionalAccess', _63 => _63.address]) && _optionalChain([client, 'access', _64 => _64.chain, 'access', _65 => _65.consensusMainContract, 'optionalAccess', _66 => _66.abi])) {
|
|
1223
1719
|
return;
|
|
1224
1720
|
}
|
|
1225
1721
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -1249,17 +1745,17 @@ var getCustomTransportConfig = (config) => {
|
|
|
1249
1745
|
return {
|
|
1250
1746
|
async request({ method, params = [] }) {
|
|
1251
1747
|
if (method.startsWith("eth_") && isAddress) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1748
|
+
const provider = config.provider || (typeof window !== "undefined" ? window.ethereum : void 0);
|
|
1749
|
+
if (provider) {
|
|
1750
|
+
try {
|
|
1751
|
+
return await provider.request({ method, params });
|
|
1752
|
+
} catch (err) {
|
|
1753
|
+
console.warn(`Error using provider for method ${method}:`, err);
|
|
1754
|
+
throw err;
|
|
1256
1755
|
}
|
|
1257
|
-
return await provider.request({ method, params });
|
|
1258
|
-
} catch (err) {
|
|
1259
|
-
console.warn(`Error using provider for method ${method}:`, err);
|
|
1260
|
-
throw err;
|
|
1261
1756
|
}
|
|
1262
|
-
}
|
|
1757
|
+
}
|
|
1758
|
+
{
|
|
1263
1759
|
if (!config.chain) {
|
|
1264
1760
|
throw new Error("Chain is not set");
|
|
1265
1761
|
}
|
|
@@ -1289,8 +1785,8 @@ var getCustomTransportConfig = (config) => {
|
|
|
1289
1785
|
}
|
|
1290
1786
|
};
|
|
1291
1787
|
};
|
|
1292
|
-
var createClient = (config = { chain:
|
|
1293
|
-
const chainConfig = config.chain ||
|
|
1788
|
+
var createClient = (config = { chain: _chunkTBF5WZHLcjs.localnet }) => {
|
|
1789
|
+
const chainConfig = config.chain || _chunkTBF5WZHLcjs.localnet;
|
|
1294
1790
|
if (config.endpoint) {
|
|
1295
1791
|
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
1296
1792
|
}
|
|
@@ -1314,10 +1810,14 @@ var createClient = (config = { chain: _chunkSMGWE7OHcjs.localnet }) => {
|
|
|
1314
1810
|
...clientWithTransactionActions,
|
|
1315
1811
|
...contractActions(clientWithTransactionActions, publicClient)
|
|
1316
1812
|
};
|
|
1317
|
-
const
|
|
1813
|
+
const clientWithReceiptActions = {
|
|
1318
1814
|
...clientWithAllActions,
|
|
1319
1815
|
...receiptActions(clientWithAllActions, publicClient)
|
|
1320
1816
|
};
|
|
1817
|
+
const finalClient = {
|
|
1818
|
+
...clientWithReceiptActions,
|
|
1819
|
+
...stakingActions(clientWithReceiptActions, publicClient)
|
|
1820
|
+
};
|
|
1321
1821
|
finalClient.initializeConsensusSmartContract().catch((error) => {
|
|
1322
1822
|
console.error("Failed to initialize consensus smart contract:", error);
|
|
1323
1823
|
});
|
|
@@ -1345,4 +1845,6 @@ var createAccount = (accountPrivateKey) => {
|
|
|
1345
1845
|
|
|
1346
1846
|
|
|
1347
1847
|
|
|
1348
|
-
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
exports.abi = abi_exports; exports.chains = _chunkTBF5WZHLcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.decodeInputData = decodeInputData; exports.decodeLocalnetTransaction = decodeLocalnetTransaction; exports.decodeTransaction = decodeTransaction; exports.formatStakingAmount = formatStakingAmount; exports.generatePrivateKey = generatePrivateKey; exports.parseStakingAmount = parseStakingAmount; exports.simplifyTransactionReceipt = simplifyTransactionReceipt;
|