genlayer-js 0.21.1 → 0.21.3
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/dist/chains/index.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkCX76PQR5cjs = require('../chunk-CX76PQR5.cjs');
|
|
7
7
|
require('../chunk-75ZPJI57.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
exports.localnet =
|
|
13
|
+
exports.localnet = _chunkCX76PQR5cjs.localnet; exports.studionet = _chunkCX76PQR5cjs.studionet; exports.testnetAsimov = _chunkCX76PQR5cjs.testnetAsimov; exports.testnetBradbury = _chunkCX76PQR5cjs.testnetBradbury;
|
package/dist/chains/index.js
CHANGED
|
@@ -9518,8 +9518,7 @@ var STAKING_ABI = [
|
|
|
9518
9518
|
];
|
|
9519
9519
|
|
|
9520
9520
|
// src/chains/testnetAsimov.ts
|
|
9521
|
-
var TESTNET_JSON_RPC_URL = "
|
|
9522
|
-
var TESTNET_WS_URL = "wss://zksync-os-testnet-genlayer.zksync.dev/ws";
|
|
9521
|
+
var TESTNET_JSON_RPC_URL = "http://34.12.136.220:9151";
|
|
9523
9522
|
var STAKING_CONTRACT = {
|
|
9524
9523
|
address: "0x63Fa5E0bb10fb6fA98F44726C5518223F767687A",
|
|
9525
9524
|
abi: STAKING_ABI
|
|
@@ -13501,8 +13500,7 @@ var testnetAsimov = _viem.defineChain.call(void 0, {
|
|
|
13501
13500
|
name: "Genlayer Asimov Testnet",
|
|
13502
13501
|
rpcUrls: {
|
|
13503
13502
|
default: {
|
|
13504
|
-
http: [TESTNET_JSON_RPC_URL]
|
|
13505
|
-
webSocket: [TESTNET_WS_URL]
|
|
13503
|
+
http: [TESTNET_JSON_RPC_URL]
|
|
13506
13504
|
}
|
|
13507
13505
|
},
|
|
13508
13506
|
nativeCurrency: {
|
|
@@ -13526,8 +13524,7 @@ var testnetAsimov = _viem.defineChain.call(void 0, {
|
|
|
13526
13524
|
|
|
13527
13525
|
// src/chains/testnetBradbury.ts
|
|
13528
13526
|
|
|
13529
|
-
var TESTNET_JSON_RPC_URL2 = "
|
|
13530
|
-
var TESTNET_WS_URL2 = "wss://zksync-os-testnet-genlayer.zksync.dev/ws";
|
|
13527
|
+
var TESTNET_JSON_RPC_URL2 = "http://34.91.102.53:9151";
|
|
13531
13528
|
var STAKING_CONTRACT2 = {
|
|
13532
13529
|
address: "0x4A4449E617F8D10FDeD0b461CadEf83939E821A5",
|
|
13533
13530
|
abi: STAKING_ABI
|
|
@@ -16855,8 +16852,7 @@ var testnetBradbury = _viem.defineChain.call(void 0, {
|
|
|
16855
16852
|
name: "Genlayer Bradbury Testnet",
|
|
16856
16853
|
rpcUrls: {
|
|
16857
16854
|
default: {
|
|
16858
|
-
http: [TESTNET_JSON_RPC_URL2]
|
|
16859
|
-
webSocket: [TESTNET_WS_URL2]
|
|
16855
|
+
http: [TESTNET_JSON_RPC_URL2]
|
|
16860
16856
|
}
|
|
16861
16857
|
},
|
|
16862
16858
|
nativeCurrency: {
|
|
@@ -9518,8 +9518,7 @@ var STAKING_ABI = [
|
|
|
9518
9518
|
];
|
|
9519
9519
|
|
|
9520
9520
|
// src/chains/testnetAsimov.ts
|
|
9521
|
-
var TESTNET_JSON_RPC_URL = "
|
|
9522
|
-
var TESTNET_WS_URL = "wss://zksync-os-testnet-genlayer.zksync.dev/ws";
|
|
9521
|
+
var TESTNET_JSON_RPC_URL = "http://34.12.136.220:9151";
|
|
9523
9522
|
var STAKING_CONTRACT = {
|
|
9524
9523
|
address: "0x63Fa5E0bb10fb6fA98F44726C5518223F767687A",
|
|
9525
9524
|
abi: STAKING_ABI
|
|
@@ -13501,8 +13500,7 @@ var testnetAsimov = defineChain3({
|
|
|
13501
13500
|
name: "Genlayer Asimov Testnet",
|
|
13502
13501
|
rpcUrls: {
|
|
13503
13502
|
default: {
|
|
13504
|
-
http: [TESTNET_JSON_RPC_URL]
|
|
13505
|
-
webSocket: [TESTNET_WS_URL]
|
|
13503
|
+
http: [TESTNET_JSON_RPC_URL]
|
|
13506
13504
|
}
|
|
13507
13505
|
},
|
|
13508
13506
|
nativeCurrency: {
|
|
@@ -13526,8 +13524,7 @@ var testnetAsimov = defineChain3({
|
|
|
13526
13524
|
|
|
13527
13525
|
// src/chains/testnetBradbury.ts
|
|
13528
13526
|
import { defineChain as defineChain4 } from "viem";
|
|
13529
|
-
var TESTNET_JSON_RPC_URL2 = "
|
|
13530
|
-
var TESTNET_WS_URL2 = "wss://zksync-os-testnet-genlayer.zksync.dev/ws";
|
|
13527
|
+
var TESTNET_JSON_RPC_URL2 = "http://34.91.102.53:9151";
|
|
13531
13528
|
var STAKING_CONTRACT2 = {
|
|
13532
13529
|
address: "0x4A4449E617F8D10FDeD0b461CadEf83939E821A5",
|
|
13533
13530
|
abi: STAKING_ABI
|
|
@@ -16855,8 +16852,7 @@ var testnetBradbury = defineChain4({
|
|
|
16855
16852
|
name: "Genlayer Bradbury Testnet",
|
|
16856
16853
|
rpcUrls: {
|
|
16857
16854
|
default: {
|
|
16858
|
-
http: [TESTNET_JSON_RPC_URL2]
|
|
16859
|
-
webSocket: [TESTNET_WS_URL2]
|
|
16855
|
+
http: [TESTNET_JSON_RPC_URL2]
|
|
16860
16856
|
}
|
|
16861
16857
|
},
|
|
16862
16858
|
nativeCurrency: {
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkCX76PQR5cjs = require('./chunk-CX76PQR5.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ var _viem = require('viem');
|
|
|
32
32
|
function accountActions(client) {
|
|
33
33
|
return {
|
|
34
34
|
fundAccount: async ({ address, amount }) => {
|
|
35
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
35
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkCX76PQR5cjs.localnet.id) {
|
|
36
36
|
throw new Error("Client is not connected to the localnet");
|
|
37
37
|
}
|
|
38
38
|
return client.request({
|
|
@@ -416,8 +416,8 @@ function serialize(data) {
|
|
|
416
416
|
// src/abi/index.ts
|
|
417
417
|
var abi_exports = {};
|
|
418
418
|
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
419
|
-
STAKING_ABI: () =>
|
|
420
|
-
VALIDATOR_WALLET_ABI: () =>
|
|
419
|
+
STAKING_ABI: () => _chunkCX76PQR5cjs.STAKING_ABI,
|
|
420
|
+
VALIDATOR_WALLET_ABI: () => _chunkCX76PQR5cjs.VALIDATOR_WALLET_ABI,
|
|
421
421
|
calldata: () => calldata,
|
|
422
422
|
transactions: () => transactions
|
|
423
423
|
});
|
|
@@ -514,10 +514,23 @@ function _toJsonSafeDeep(value, seen) {
|
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
// src/contracts/actions.ts
|
|
517
|
+
function extractGenCallResult(result) {
|
|
518
|
+
if (typeof result === "string") {
|
|
519
|
+
return `0x${result}`;
|
|
520
|
+
}
|
|
521
|
+
if (result && typeof result === "object" && "data" in result) {
|
|
522
|
+
const obj = result;
|
|
523
|
+
if (obj.status && obj.status.code !== 0) {
|
|
524
|
+
throw new Error(`gen_call failed: ${obj.status.message}`);
|
|
525
|
+
}
|
|
526
|
+
return `0x${obj.data}`;
|
|
527
|
+
}
|
|
528
|
+
throw new Error(`Unexpected gen_call response: ${JSON.stringify(result)}`);
|
|
529
|
+
}
|
|
517
530
|
var contractActions = (client, publicClient) => {
|
|
518
531
|
return {
|
|
519
532
|
getContractCode: async (address) => {
|
|
520
|
-
if (client.chain.id !==
|
|
533
|
+
if (client.chain.id !== _chunkCX76PQR5cjs.localnet.id) {
|
|
521
534
|
throw new Error("Getting contract code is not supported on this network");
|
|
522
535
|
}
|
|
523
536
|
const result = await client.request({
|
|
@@ -528,7 +541,7 @@ var contractActions = (client, publicClient) => {
|
|
|
528
541
|
return new TextDecoder().decode(codeBytes);
|
|
529
542
|
},
|
|
530
543
|
getContractSchema: async (address) => {
|
|
531
|
-
if (client.chain.id !==
|
|
544
|
+
if (client.chain.id !== _chunkCX76PQR5cjs.localnet.id) {
|
|
532
545
|
throw new Error("Contract schema is not supported on this network");
|
|
533
546
|
}
|
|
534
547
|
const schema = await client.request({
|
|
@@ -538,7 +551,7 @@ var contractActions = (client, publicClient) => {
|
|
|
538
551
|
return schema;
|
|
539
552
|
},
|
|
540
553
|
getContractSchemaForCode: async (contractCode) => {
|
|
541
|
-
if (client.chain.id !==
|
|
554
|
+
if (client.chain.id !== _chunkCX76PQR5cjs.localnet.id) {
|
|
542
555
|
throw new Error("Contract schema is not supported on this network");
|
|
543
556
|
}
|
|
544
557
|
const schema = await client.request({
|
|
@@ -572,7 +585,7 @@ var contractActions = (client, publicClient) => {
|
|
|
572
585
|
method: "gen_call",
|
|
573
586
|
params: [requestParams]
|
|
574
587
|
});
|
|
575
|
-
const prefixedResult =
|
|
588
|
+
const prefixedResult = extractGenCallResult(result);
|
|
576
589
|
if (args.rawReturn) {
|
|
577
590
|
return prefixedResult;
|
|
578
591
|
}
|
|
@@ -607,7 +620,7 @@ var contractActions = (client, publicClient) => {
|
|
|
607
620
|
method: "gen_call",
|
|
608
621
|
params: [requestParams]
|
|
609
622
|
});
|
|
610
|
-
const prefixedResult =
|
|
623
|
+
const prefixedResult = extractGenCallResult(result);
|
|
611
624
|
if (args.rawReturn) {
|
|
612
625
|
return prefixedResult;
|
|
613
626
|
}
|
|
@@ -1006,36 +1019,37 @@ var decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
|
1006
1019
|
}
|
|
1007
1020
|
};
|
|
1008
1021
|
var decodeTransaction = (tx) => {
|
|
1009
|
-
const
|
|
1022
|
+
const txData = _nullishCoalesce(tx.txData, () => ( tx.txCalldata));
|
|
1023
|
+
const numOfInitialValidators = _nullishCoalesce(tx.numOfInitialValidators, () => ( tx.initialRotations));
|
|
1024
|
+
const txDataDecoded = decodeInputData(txData, tx.recipient);
|
|
1010
1025
|
const decodedTx = {
|
|
1011
1026
|
...tx,
|
|
1012
|
-
txData
|
|
1027
|
+
txData,
|
|
1013
1028
|
txDataDecoded,
|
|
1014
|
-
currentTimestamp:
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
numOfRounds: _nullishCoalesce(_optionalChain([tx, 'access', _55 => _55.numOfRounds, 'optionalAccess', _56 => _56.toString, 'call', _57 => _57()]), () => ( "0")),
|
|
1029
|
+
currentTimestamp: tx.currentTimestamp.toString(),
|
|
1030
|
+
numOfInitialValidators: _nullishCoalesce(_optionalChain([numOfInitialValidators, 'optionalAccess', _38 => _38.toString, 'call', _39 => _39()]), () => ( "0")),
|
|
1031
|
+
txSlot: tx.txSlot.toString(),
|
|
1032
|
+
createdTimestamp: tx.createdTimestamp.toString(),
|
|
1033
|
+
lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
|
|
1034
|
+
queuePosition: tx.queuePosition.toString(),
|
|
1035
|
+
numOfRounds: tx.numOfRounds.toString(),
|
|
1022
1036
|
readStateBlockRange: {
|
|
1023
1037
|
...tx.readStateBlockRange,
|
|
1024
|
-
activationBlock: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1025
|
-
processingBlock: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1026
|
-
proposalBlock: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1038
|
+
activationBlock: _nullishCoalesce(_optionalChain([tx, 'access', _40 => _40.readStateBlockRange, 'optionalAccess', _41 => _41.activationBlock, 'optionalAccess', _42 => _42.toString, 'call', _43 => _43()]), () => ( "0")),
|
|
1039
|
+
processingBlock: _nullishCoalesce(_optionalChain([tx, 'access', _44 => _44.readStateBlockRange, 'optionalAccess', _45 => _45.processingBlock, 'optionalAccess', _46 => _46.toString, 'call', _47 => _47()]), () => ( "0")),
|
|
1040
|
+
proposalBlock: _nullishCoalesce(_optionalChain([tx, 'access', _48 => _48.readStateBlockRange, 'optionalAccess', _49 => _49.proposalBlock, 'optionalAccess', _50 => _50.toString, 'call', _51 => _51()]), () => ( "0"))
|
|
1027
1041
|
},
|
|
1028
1042
|
statusName: _chunkW4V73RPNcjs.transactionsStatusNumberToName[String(tx.status)],
|
|
1029
1043
|
resultName: _chunkW4V73RPNcjs.transactionResultNumberToName[String(tx.result)],
|
|
1030
1044
|
lastRound: {
|
|
1031
1045
|
...tx.lastRound,
|
|
1032
|
-
round: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1033
|
-
leaderIndex: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1034
|
-
votesCommitted: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1035
|
-
votesRevealed: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1036
|
-
appealBond: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1037
|
-
rotationsLeft: _nullishCoalesce(_optionalChain([tx, 'access',
|
|
1038
|
-
validatorVotesName: (_nullishCoalesce(_optionalChain([tx, 'access',
|
|
1046
|
+
round: _nullishCoalesce(_optionalChain([tx, 'access', _52 => _52.lastRound, 'optionalAccess', _53 => _53.round, 'optionalAccess', _54 => _54.toString, 'call', _55 => _55()]), () => ( "0")),
|
|
1047
|
+
leaderIndex: _nullishCoalesce(_optionalChain([tx, 'access', _56 => _56.lastRound, 'optionalAccess', _57 => _57.leaderIndex, 'optionalAccess', _58 => _58.toString, 'call', _59 => _59()]), () => ( "0")),
|
|
1048
|
+
votesCommitted: _nullishCoalesce(_optionalChain([tx, 'access', _60 => _60.lastRound, 'optionalAccess', _61 => _61.votesCommitted, 'optionalAccess', _62 => _62.toString, 'call', _63 => _63()]), () => ( "0")),
|
|
1049
|
+
votesRevealed: _nullishCoalesce(_optionalChain([tx, 'access', _64 => _64.lastRound, 'optionalAccess', _65 => _65.votesRevealed, 'optionalAccess', _66 => _66.toString, 'call', _67 => _67()]), () => ( "0")),
|
|
1050
|
+
appealBond: _nullishCoalesce(_optionalChain([tx, 'access', _68 => _68.lastRound, 'optionalAccess', _69 => _69.appealBond, 'optionalAccess', _70 => _70.toString, 'call', _71 => _71()]), () => ( "0")),
|
|
1051
|
+
rotationsLeft: _nullishCoalesce(_optionalChain([tx, 'access', _72 => _72.lastRound, 'optionalAccess', _73 => _73.rotationsLeft, 'optionalAccess', _74 => _74.toString, 'call', _75 => _75()]), () => ( "0")),
|
|
1052
|
+
validatorVotesName: (_nullishCoalesce(_optionalChain([tx, 'access', _76 => _76.lastRound, 'optionalAccess', _77 => _77.validatorVotes]), () => ( []))).map(
|
|
1039
1053
|
(vote) => _chunkW4V73RPNcjs.voteTypeNumberToName[String(vote)]
|
|
1040
1054
|
)
|
|
1041
1055
|
}
|
|
@@ -1117,7 +1131,7 @@ var simplifyTransactionReceipt = (tx) => {
|
|
|
1117
1131
|
var decodeLocalnetTransaction = (tx) => {
|
|
1118
1132
|
if (!tx.data) return tx;
|
|
1119
1133
|
try {
|
|
1120
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
1134
|
+
const leaderReceipt = _optionalChain([tx, 'access', _78 => _78.consensus_data, 'optionalAccess', _79 => _79.leader_receipt]);
|
|
1121
1135
|
if (leaderReceipt) {
|
|
1122
1136
|
const receipts = Array.isArray(leaderReceipt) ? leaderReceipt : [leaderReceipt];
|
|
1123
1137
|
receipts.forEach((receipt) => {
|
|
@@ -1148,7 +1162,7 @@ var decodeLocalnetTransaction = (tx) => {
|
|
|
1148
1162
|
}
|
|
1149
1163
|
});
|
|
1150
1164
|
}
|
|
1151
|
-
if (_optionalChain([tx, 'access',
|
|
1165
|
+
if (_optionalChain([tx, 'access', _80 => _80.data, 'optionalAccess', _81 => _81.calldata]) && typeof tx.data.calldata === "string") {
|
|
1152
1166
|
tx.data.calldata = {
|
|
1153
1167
|
base64: tx.data.calldata,
|
|
1154
1168
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -1179,7 +1193,7 @@ var receiptActions = (client, publicClient) => ({
|
|
|
1179
1193
|
const requestedStatus = _chunkW4V73RPNcjs.transactionsStatusNameToNumber[status];
|
|
1180
1194
|
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && _chunkW4V73RPNcjs.isDecidedState.call(void 0, transactionStatusString)) {
|
|
1181
1195
|
let finalTransaction = transaction;
|
|
1182
|
-
if (client.chain.id ===
|
|
1196
|
+
if (client.chain.id === _chunkCX76PQR5cjs.localnet.id) {
|
|
1183
1197
|
finalTransaction = decodeLocalnetTransaction(transaction);
|
|
1184
1198
|
}
|
|
1185
1199
|
if (!fullTransaction) {
|
|
@@ -1210,8 +1224,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1210
1224
|
return decodeLocalnetTransaction(transaction2);
|
|
1211
1225
|
}
|
|
1212
1226
|
const transaction = await publicClient.readContract({
|
|
1213
|
-
address: _optionalChain([client, 'access',
|
|
1214
|
-
abi: _optionalChain([client, 'access',
|
|
1227
|
+
address: _optionalChain([client, 'access', _82 => _82.chain, 'access', _83 => _83.consensusDataContract, 'optionalAccess', _84 => _84.address]),
|
|
1228
|
+
abi: _optionalChain([client, 'access', _85 => _85.chain, 'access', _86 => _86.consensusDataContract, 'optionalAccess', _87 => _87.abi]),
|
|
1215
1229
|
functionName: "getTransactionData",
|
|
1216
1230
|
args: [
|
|
1217
1231
|
hash,
|
|
@@ -1250,7 +1264,7 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1250
1264
|
},
|
|
1251
1265
|
estimateTransactionGas: async (transactionParams) => {
|
|
1252
1266
|
const formattedParams = {
|
|
1253
|
-
from: transactionParams.from || _optionalChain([client, 'access',
|
|
1267
|
+
from: transactionParams.from || _optionalChain([client, 'access', _88 => _88.account, 'optionalAccess', _89 => _89.address]),
|
|
1254
1268
|
to: transactionParams.to,
|
|
1255
1269
|
data: transactionParams.data || "0x",
|
|
1256
1270
|
value: transactionParams.value ? `0x${transactionParams.value.toString(16)}` : "0x0"
|
|
@@ -1271,10 +1285,10 @@ var snapID = {
|
|
|
1271
1285
|
|
|
1272
1286
|
// src/wallet/connect.ts
|
|
1273
1287
|
var networks = {
|
|
1274
|
-
localnet:
|
|
1275
|
-
studionet:
|
|
1276
|
-
testnetAsimov:
|
|
1277
|
-
testnetBradbury:
|
|
1288
|
+
localnet: _chunkCX76PQR5cjs.localnet,
|
|
1289
|
+
studionet: _chunkCX76PQR5cjs.studionet,
|
|
1290
|
+
testnetAsimov: _chunkCX76PQR5cjs.testnetAsimov,
|
|
1291
|
+
testnetBradbury: _chunkCX76PQR5cjs.testnetBradbury
|
|
1278
1292
|
};
|
|
1279
1293
|
var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
1280
1294
|
if (!window.ethereum) {
|
|
@@ -1293,7 +1307,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
1293
1307
|
chainName: selectedNetwork.name,
|
|
1294
1308
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
1295
1309
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
1296
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
1310
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _90 => _90.blockExplorers, 'optionalAccess', _91 => _91.default, 'access', _92 => _92.url])]
|
|
1297
1311
|
};
|
|
1298
1312
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
1299
1313
|
if (currentChainId !== chainIdHex) {
|
|
@@ -1327,10 +1341,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1327
1341
|
}
|
|
1328
1342
|
const isFlask = async () => {
|
|
1329
1343
|
try {
|
|
1330
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
1344
|
+
const clientVersion = await _optionalChain([window, 'access', _93 => _93.ethereum, 'optionalAccess', _94 => _94.request, 'call', _95 => _95({
|
|
1331
1345
|
method: "web3_clientVersion"
|
|
1332
1346
|
})]);
|
|
1333
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
1347
|
+
return _optionalChain([clientVersion, 'optionalAccess', _96 => _96.includes, 'call', _97 => _97("flask")]);
|
|
1334
1348
|
} catch (error) {
|
|
1335
1349
|
console.error("Error detecting Flask:", error);
|
|
1336
1350
|
return false;
|
|
@@ -1338,7 +1352,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1338
1352
|
};
|
|
1339
1353
|
const installedSnaps = async () => {
|
|
1340
1354
|
try {
|
|
1341
|
-
return await _optionalChain([window, 'access',
|
|
1355
|
+
return await _optionalChain([window, 'access', _98 => _98.ethereum, 'optionalAccess', _99 => _99.request, 'call', _100 => _100({
|
|
1342
1356
|
method: "wallet_getSnaps"
|
|
1343
1357
|
})]);
|
|
1344
1358
|
} catch (error) {
|
|
@@ -1390,7 +1404,7 @@ function formatStakingAmount(amount) {
|
|
|
1390
1404
|
// src/staking/actions.ts
|
|
1391
1405
|
var FALLBACK_GAS = 1000000n;
|
|
1392
1406
|
var GAS_BUFFER_MULTIPLIER = 2n;
|
|
1393
|
-
var COMBINED_ERROR_ABI = [...
|
|
1407
|
+
var COMBINED_ERROR_ABI = [..._chunkCX76PQR5cjs.STAKING_ABI, ..._chunkCX76PQR5cjs.VALIDATOR_WALLET_ABI];
|
|
1394
1408
|
function extractRevertReason(err) {
|
|
1395
1409
|
if (err instanceof _viem.BaseError) {
|
|
1396
1410
|
const rawError = err.walk((e) => e instanceof _viem.RawContractError);
|
|
@@ -1425,7 +1439,7 @@ function extractRevertReason(err) {
|
|
|
1425
1439
|
}
|
|
1426
1440
|
const revertError = err.walk((e) => e instanceof _viem.ContractFunctionRevertedError);
|
|
1427
1441
|
if (revertError instanceof _viem.ContractFunctionRevertedError) {
|
|
1428
|
-
if (_optionalChain([revertError, 'access',
|
|
1442
|
+
if (_optionalChain([revertError, 'access', _101 => _101.data, 'optionalAccess', _102 => _102.errorName])) {
|
|
1429
1443
|
return revertError.data.errorName;
|
|
1430
1444
|
}
|
|
1431
1445
|
return revertError.reason || "Unknown reason";
|
|
@@ -1513,7 +1527,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1513
1527
|
};
|
|
1514
1528
|
const getStakingAddress = () => {
|
|
1515
1529
|
const stakingConfig = client.chain.stakingContract;
|
|
1516
|
-
if (!_optionalChain([stakingConfig, 'optionalAccess',
|
|
1530
|
+
if (!_optionalChain([stakingConfig, 'optionalAccess', _103 => _103.address]) || stakingConfig.address === "0x0000000000000000000000000000000000000000") {
|
|
1517
1531
|
throw new Error("Staking is not supported on studio-based networks. Use testnet-asimov for staking operations.");
|
|
1518
1532
|
}
|
|
1519
1533
|
return stakingConfig.address;
|
|
@@ -1522,7 +1536,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1522
1536
|
const address = getStakingAddress();
|
|
1523
1537
|
return _viem.getContract.call(void 0, {
|
|
1524
1538
|
address,
|
|
1525
|
-
abi:
|
|
1539
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1526
1540
|
client: { public: publicClient, wallet: client }
|
|
1527
1541
|
});
|
|
1528
1542
|
};
|
|
@@ -1530,7 +1544,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1530
1544
|
const address = getStakingAddress();
|
|
1531
1545
|
return _viem.getContract.call(void 0, {
|
|
1532
1546
|
address,
|
|
1533
|
-
abi:
|
|
1547
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1534
1548
|
client: publicClient
|
|
1535
1549
|
});
|
|
1536
1550
|
};
|
|
@@ -1539,11 +1553,11 @@ var stakingActions = (client, publicClient) => {
|
|
|
1539
1553
|
const amount = parseStakingAmount(options.amount);
|
|
1540
1554
|
const stakingAddress = getStakingAddress();
|
|
1541
1555
|
const data = options.operator ? _viem.encodeFunctionData.call(void 0, {
|
|
1542
|
-
abi:
|
|
1556
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1543
1557
|
functionName: "validatorJoin",
|
|
1544
1558
|
args: [options.operator]
|
|
1545
1559
|
}) : _viem.encodeFunctionData.call(void 0, {
|
|
1546
|
-
abi:
|
|
1560
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1547
1561
|
functionName: "validatorJoin"
|
|
1548
1562
|
});
|
|
1549
1563
|
const result = await executeWrite({ to: stakingAddress, data, value: amount });
|
|
@@ -1552,7 +1566,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1552
1566
|
let eventFound = false;
|
|
1553
1567
|
for (const log of receipt.logs) {
|
|
1554
1568
|
try {
|
|
1555
|
-
const decoded = _viem.decodeEventLog.call(void 0, { abi:
|
|
1569
|
+
const decoded = _viem.decodeEventLog.call(void 0, { abi: _chunkCX76PQR5cjs.STAKING_ABI, data: log.data, topics: log.topics });
|
|
1556
1570
|
if (decoded.eventName === "ValidatorJoin") {
|
|
1557
1571
|
validatorWallet = decoded.args.validator;
|
|
1558
1572
|
eventFound = true;
|
|
@@ -1579,7 +1593,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1579
1593
|
validatorDeposit: async (options) => {
|
|
1580
1594
|
const amount = parseStakingAmount(options.amount);
|
|
1581
1595
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1582
|
-
abi:
|
|
1596
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1583
1597
|
functionName: "validatorDeposit"
|
|
1584
1598
|
});
|
|
1585
1599
|
return executeWrite({ to: getStakingAddress(), data, value: amount });
|
|
@@ -1587,19 +1601,19 @@ var stakingActions = (client, publicClient) => {
|
|
|
1587
1601
|
validatorExit: async (options) => {
|
|
1588
1602
|
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1589
1603
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1590
|
-
abi:
|
|
1604
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1591
1605
|
functionName: "validatorExit",
|
|
1592
1606
|
args: [shares]
|
|
1593
1607
|
});
|
|
1594
1608
|
return executeWrite({ to: getStakingAddress(), data });
|
|
1595
1609
|
},
|
|
1596
1610
|
validatorClaim: async (options) => {
|
|
1597
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1611
|
+
if (!_optionalChain([options, 'optionalAccess', _104 => _104.validator]) && !client.account) {
|
|
1598
1612
|
throw new Error("Either provide validator address or initialize client with an account");
|
|
1599
1613
|
}
|
|
1600
|
-
const validatorAddress = _optionalChain([options, 'optionalAccess',
|
|
1614
|
+
const validatorAddress = _optionalChain([options, 'optionalAccess', _105 => _105.validator]) || client.account.address;
|
|
1601
1615
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1602
|
-
abi:
|
|
1616
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1603
1617
|
functionName: "validatorClaim",
|
|
1604
1618
|
args: [validatorAddress]
|
|
1605
1619
|
});
|
|
@@ -1608,7 +1622,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1608
1622
|
},
|
|
1609
1623
|
validatorPrime: async (options) => {
|
|
1610
1624
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1611
|
-
abi:
|
|
1625
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1612
1626
|
functionName: "validatorPrime",
|
|
1613
1627
|
args: [options.validator]
|
|
1614
1628
|
});
|
|
@@ -1616,7 +1630,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1616
1630
|
},
|
|
1617
1631
|
setOperator: async (options) => {
|
|
1618
1632
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1619
|
-
abi:
|
|
1633
|
+
abi: _chunkCX76PQR5cjs.VALIDATOR_WALLET_ABI,
|
|
1620
1634
|
functionName: "setOperator",
|
|
1621
1635
|
args: [options.operator]
|
|
1622
1636
|
});
|
|
@@ -1632,7 +1646,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1632
1646
|
}
|
|
1633
1647
|
}
|
|
1634
1648
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1635
|
-
abi:
|
|
1649
|
+
abi: _chunkCX76PQR5cjs.VALIDATOR_WALLET_ABI,
|
|
1636
1650
|
functionName: "setIdentity",
|
|
1637
1651
|
args: [
|
|
1638
1652
|
options.moniker,
|
|
@@ -1651,7 +1665,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1651
1665
|
delegatorJoin: async (options) => {
|
|
1652
1666
|
const amount = parseStakingAmount(options.amount);
|
|
1653
1667
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1654
|
-
abi:
|
|
1668
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1655
1669
|
functionName: "delegatorJoin",
|
|
1656
1670
|
args: [options.validator]
|
|
1657
1671
|
});
|
|
@@ -1667,7 +1681,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1667
1681
|
delegatorExit: async (options) => {
|
|
1668
1682
|
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1669
1683
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1670
|
-
abi:
|
|
1684
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1671
1685
|
functionName: "delegatorExit",
|
|
1672
1686
|
args: [options.validator, shares]
|
|
1673
1687
|
});
|
|
@@ -1679,7 +1693,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1679
1693
|
}
|
|
1680
1694
|
const delegatorAddress = options.delegator || client.account.address;
|
|
1681
1695
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1682
|
-
abi:
|
|
1696
|
+
abi: _chunkCX76PQR5cjs.STAKING_ABI,
|
|
1683
1697
|
functionName: "delegatorClaim",
|
|
1684
1698
|
args: [delegatorAddress, options.validator]
|
|
1685
1699
|
});
|
|
@@ -1697,7 +1711,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1697
1711
|
}
|
|
1698
1712
|
const walletContract = _viem.getContract.call(void 0, {
|
|
1699
1713
|
address: validator,
|
|
1700
|
-
abi:
|
|
1714
|
+
abi: _chunkCX76PQR5cjs.VALIDATOR_WALLET_ABI,
|
|
1701
1715
|
client: publicClient
|
|
1702
1716
|
});
|
|
1703
1717
|
const [view, owner, operator, identityRaw, currentEpoch] = await Promise.all([
|
|
@@ -1992,8 +2006,8 @@ var getCustomTransportConfig = (config, chainConfig) => {
|
|
|
1992
2006
|
}
|
|
1993
2007
|
};
|
|
1994
2008
|
};
|
|
1995
|
-
var createClient = (config = { chain:
|
|
1996
|
-
const chainConfig = config.chain ||
|
|
2009
|
+
var createClient = (config = { chain: _chunkCX76PQR5cjs.localnet }) => {
|
|
2010
|
+
const chainConfig = config.chain || _chunkCX76PQR5cjs.localnet;
|
|
1997
2011
|
if (config.endpoint) {
|
|
1998
2012
|
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
1999
2013
|
}
|
|
@@ -2130,4 +2144,4 @@ function validateValueAgainstType(value, type) {
|
|
|
2130
2144
|
|
|
2131
2145
|
|
|
2132
2146
|
|
|
2133
|
-
exports.abi = abi_exports; exports.buildGenVmPositionalArgs = buildGenVmPositionalArgs; exports.chains =
|
|
2147
|
+
exports.abi = abi_exports; exports.buildGenVmPositionalArgs = buildGenVmPositionalArgs; exports.chains = _chunkCX76PQR5cjs.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;
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
studionet,
|
|
7
7
|
testnetAsimov,
|
|
8
8
|
testnetBradbury
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-T3O6IXYQ.js";
|
|
10
10
|
import {
|
|
11
11
|
CalldataAddress,
|
|
12
12
|
isDecidedState,
|
|
@@ -514,6 +514,19 @@ function _toJsonSafeDeep(value, seen) {
|
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
// src/contracts/actions.ts
|
|
517
|
+
function extractGenCallResult(result) {
|
|
518
|
+
if (typeof result === "string") {
|
|
519
|
+
return `0x${result}`;
|
|
520
|
+
}
|
|
521
|
+
if (result && typeof result === "object" && "data" in result) {
|
|
522
|
+
const obj = result;
|
|
523
|
+
if (obj.status && obj.status.code !== 0) {
|
|
524
|
+
throw new Error(`gen_call failed: ${obj.status.message}`);
|
|
525
|
+
}
|
|
526
|
+
return `0x${obj.data}`;
|
|
527
|
+
}
|
|
528
|
+
throw new Error(`Unexpected gen_call response: ${JSON.stringify(result)}`);
|
|
529
|
+
}
|
|
517
530
|
var contractActions = (client, publicClient) => {
|
|
518
531
|
return {
|
|
519
532
|
getContractCode: async (address) => {
|
|
@@ -572,7 +585,7 @@ var contractActions = (client, publicClient) => {
|
|
|
572
585
|
method: "gen_call",
|
|
573
586
|
params: [requestParams]
|
|
574
587
|
});
|
|
575
|
-
const prefixedResult =
|
|
588
|
+
const prefixedResult = extractGenCallResult(result);
|
|
576
589
|
if (args.rawReturn) {
|
|
577
590
|
return prefixedResult;
|
|
578
591
|
}
|
|
@@ -607,7 +620,7 @@ var contractActions = (client, publicClient) => {
|
|
|
607
620
|
method: "gen_call",
|
|
608
621
|
params: [requestParams]
|
|
609
622
|
});
|
|
610
|
-
const prefixedResult =
|
|
623
|
+
const prefixedResult = extractGenCallResult(result);
|
|
611
624
|
if (args.rawReturn) {
|
|
612
625
|
return prefixedResult;
|
|
613
626
|
}
|
|
@@ -1006,19 +1019,20 @@ var decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
|
1006
1019
|
}
|
|
1007
1020
|
};
|
|
1008
1021
|
var decodeTransaction = (tx) => {
|
|
1009
|
-
const
|
|
1022
|
+
const txData = tx.txData ?? tx.txCalldata;
|
|
1023
|
+
const numOfInitialValidators = tx.numOfInitialValidators ?? tx.initialRotations;
|
|
1024
|
+
const txDataDecoded = decodeInputData(txData, tx.recipient);
|
|
1010
1025
|
const decodedTx = {
|
|
1011
1026
|
...tx,
|
|
1012
|
-
txData
|
|
1027
|
+
txData,
|
|
1013
1028
|
txDataDecoded,
|
|
1014
|
-
currentTimestamp: tx.currentTimestamp
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
numOfRounds: tx.numOfRounds?.toString() ?? "0",
|
|
1029
|
+
currentTimestamp: tx.currentTimestamp.toString(),
|
|
1030
|
+
numOfInitialValidators: numOfInitialValidators?.toString() ?? "0",
|
|
1031
|
+
txSlot: tx.txSlot.toString(),
|
|
1032
|
+
createdTimestamp: tx.createdTimestamp.toString(),
|
|
1033
|
+
lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
|
|
1034
|
+
queuePosition: tx.queuePosition.toString(),
|
|
1035
|
+
numOfRounds: tx.numOfRounds.toString(),
|
|
1022
1036
|
readStateBlockRange: {
|
|
1023
1037
|
...tx.readStateBlockRange,
|
|
1024
1038
|
activationBlock: tx.readStateBlockRange?.activationBlock?.toString() ?? "0",
|