genlayer-js 0.18.7 → 0.18.9
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 +4 -0
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/{chunk-I23SLL2A.cjs → chunk-SC2VXHL3.cjs} +102 -2
- package/dist/{chunk-RW6PLN5W.js → chunk-V3MYVW3P.js} +102 -2
- package/dist/{index-DM646L5c.d.cts → index-D9ONjYgl.d.cts} +162 -22
- package/dist/{index-9QkkDjYm.d.ts → index-ZDqJWXj0.d.ts} +162 -22
- package/dist/index.cjs +133 -94
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +88 -49
- 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 +122 -0
- package/src/client/client.ts +3 -7
- package/src/contracts/actions.ts +60 -41
- package/src/staking/actions.ts +49 -11
- package/src/types/staking.ts +4 -7
- package/src/types/transactions.ts +16 -14
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkSC2VXHL3cjs = require('./chunk-SC2VXHL3.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ var _viem = require('viem');
|
|
|
31
31
|
function accountActions(client) {
|
|
32
32
|
return {
|
|
33
33
|
fundAccount: async ({ address, amount }) => {
|
|
34
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
34
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkSC2VXHL3cjs.localnet.id) {
|
|
35
35
|
throw new Error("Client is not connected to the localnet");
|
|
36
36
|
}
|
|
37
37
|
return client.request({
|
|
@@ -415,8 +415,8 @@ function serialize(data) {
|
|
|
415
415
|
// src/abi/index.ts
|
|
416
416
|
var abi_exports = {};
|
|
417
417
|
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
418
|
-
STAKING_ABI: () =>
|
|
419
|
-
VALIDATOR_WALLET_ABI: () =>
|
|
418
|
+
STAKING_ABI: () => _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
419
|
+
VALIDATOR_WALLET_ABI: () => _chunkSC2VXHL3cjs.VALIDATOR_WALLET_ABI,
|
|
420
420
|
calldata: () => calldata,
|
|
421
421
|
transactions: () => transactions
|
|
422
422
|
});
|
|
@@ -516,7 +516,7 @@ function _toJsonSafeDeep(value, seen) {
|
|
|
516
516
|
var contractActions = (client, publicClient) => {
|
|
517
517
|
return {
|
|
518
518
|
getContractCode: async (address) => {
|
|
519
|
-
if (client.chain.id !==
|
|
519
|
+
if (client.chain.id !== _chunkSC2VXHL3cjs.localnet.id) {
|
|
520
520
|
throw new Error("Getting contract code is not supported on this network");
|
|
521
521
|
}
|
|
522
522
|
const result = await client.request({
|
|
@@ -527,7 +527,7 @@ var contractActions = (client, publicClient) => {
|
|
|
527
527
|
return new TextDecoder().decode(codeBytes);
|
|
528
528
|
},
|
|
529
529
|
getContractSchema: async (address) => {
|
|
530
|
-
if (client.chain.id !==
|
|
530
|
+
if (client.chain.id !== _chunkSC2VXHL3cjs.localnet.id) {
|
|
531
531
|
throw new Error("Contract schema is not supported on this network");
|
|
532
532
|
}
|
|
533
533
|
const schema = await client.request({
|
|
@@ -537,7 +537,7 @@ var contractActions = (client, publicClient) => {
|
|
|
537
537
|
return schema;
|
|
538
538
|
},
|
|
539
539
|
getContractSchemaForCode: async (contractCode) => {
|
|
540
|
-
if (client.chain.id !==
|
|
540
|
+
if (client.chain.id !== _chunkSC2VXHL3cjs.localnet.id) {
|
|
541
541
|
throw new Error("Contract schema is not supported on this network");
|
|
542
542
|
}
|
|
543
543
|
const schema = await client.request({
|
|
@@ -743,50 +743,64 @@ var _sendTransaction = async ({
|
|
|
743
743
|
data: encodedData,
|
|
744
744
|
value
|
|
745
745
|
});
|
|
746
|
-
} catch (
|
|
747
|
-
console.
|
|
746
|
+
} catch (err) {
|
|
747
|
+
console.error("Gas estimation failed, using default 200_000:", err);
|
|
748
748
|
estimatedGas = 200000n;
|
|
749
749
|
}
|
|
750
|
+
if (_optionalChain([validatedSenderAccount, 'optionalAccess', _23 => _23.type]) === "local") {
|
|
751
|
+
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _24 => _24.signTransaction])) {
|
|
752
|
+
throw new Error("Account does not support signTransaction");
|
|
753
|
+
}
|
|
754
|
+
const gasPriceHex = await client.request({
|
|
755
|
+
method: "eth_gasPrice"
|
|
756
|
+
});
|
|
757
|
+
const transactionRequest2 = {
|
|
758
|
+
account: validatedSenderAccount,
|
|
759
|
+
to: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusMainContract, 'optionalAccess', _27 => _27.address]),
|
|
760
|
+
data: encodedData,
|
|
761
|
+
type: "legacy",
|
|
762
|
+
nonce: Number(nonce),
|
|
763
|
+
value,
|
|
764
|
+
gas: estimatedGas,
|
|
765
|
+
gasPrice: BigInt(gasPriceHex),
|
|
766
|
+
chainId: client.chain.id
|
|
767
|
+
};
|
|
768
|
+
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest2);
|
|
769
|
+
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
770
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
771
|
+
if (receipt.status === "reverted") {
|
|
772
|
+
throw new Error("Transaction reverted");
|
|
773
|
+
}
|
|
774
|
+
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
775
|
+
abi: _optionalChain([client, 'access', _28 => _28.chain, 'access', _29 => _29.consensusMainContract, 'optionalAccess', _30 => _30.abi]),
|
|
776
|
+
eventName: "NewTransaction",
|
|
777
|
+
logs: receipt.logs
|
|
778
|
+
});
|
|
779
|
+
if (newTxEvents.length === 0) {
|
|
780
|
+
throw new Error("Transaction not processed by consensus");
|
|
781
|
+
}
|
|
782
|
+
return newTxEvents[0].args["txId"];
|
|
783
|
+
}
|
|
750
784
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
751
785
|
account: validatedSenderAccount,
|
|
752
|
-
to: _optionalChain([client, 'access',
|
|
786
|
+
to: _optionalChain([client, 'access', _31 => _31.chain, 'access', _32 => _32.consensusMainContract, 'optionalAccess', _33 => _33.address]),
|
|
753
787
|
data: encodedData,
|
|
754
788
|
type: "legacy",
|
|
755
789
|
nonce: Number(nonce),
|
|
756
790
|
value,
|
|
757
791
|
gas: estimatedGas
|
|
758
792
|
});
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
params: [formattedRequest]
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _27 => _27.signTransaction])) {
|
|
773
|
-
throw new Error("Account does not support signTransaction");
|
|
774
|
-
}
|
|
775
|
-
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
776
|
-
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
777
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
778
|
-
if (receipt.status === "reverted") {
|
|
779
|
-
throw new Error("Transaction reverted");
|
|
780
|
-
}
|
|
781
|
-
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
782
|
-
abi: _optionalChain([client, 'access', _28 => _28.chain, 'access', _29 => _29.consensusMainContract, 'optionalAccess', _30 => _30.abi]),
|
|
783
|
-
eventName: "NewTransaction",
|
|
784
|
-
logs: receipt.logs
|
|
793
|
+
const formattedRequest = {
|
|
794
|
+
from: transactionRequest.from,
|
|
795
|
+
to: transactionRequest.to,
|
|
796
|
+
data: encodedData,
|
|
797
|
+
value: transactionRequest.value ? `0x${transactionRequest.value.toString(16)}` : "0x0",
|
|
798
|
+
gas: transactionRequest.gas ? `0x${transactionRequest.gas.toString(16)}` : "0x5208"
|
|
799
|
+
};
|
|
800
|
+
return await client.request({
|
|
801
|
+
method: "eth_sendTransaction",
|
|
802
|
+
params: [formattedRequest]
|
|
785
803
|
});
|
|
786
|
-
if (newTxEvents.length === 0) {
|
|
787
|
-
throw new Error("Transaction not processed by consensus");
|
|
788
|
-
}
|
|
789
|
-
return newTxEvents[0].args["txId"];
|
|
790
804
|
};
|
|
791
805
|
|
|
792
806
|
// src/config/transactions.ts
|
|
@@ -992,7 +1006,7 @@ var simplifyTransactionReceipt = (tx) => {
|
|
|
992
1006
|
var decodeLocalnetTransaction = (tx) => {
|
|
993
1007
|
if (!tx.data) return tx;
|
|
994
1008
|
try {
|
|
995
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
1009
|
+
const leaderReceipt = _optionalChain([tx, 'access', _34 => _34.consensus_data, 'optionalAccess', _35 => _35.leader_receipt]);
|
|
996
1010
|
if (leaderReceipt) {
|
|
997
1011
|
const receipts = Array.isArray(leaderReceipt) ? leaderReceipt : [leaderReceipt];
|
|
998
1012
|
receipts.forEach((receipt) => {
|
|
@@ -1023,7 +1037,7 @@ var decodeLocalnetTransaction = (tx) => {
|
|
|
1023
1037
|
}
|
|
1024
1038
|
});
|
|
1025
1039
|
}
|
|
1026
|
-
if (_optionalChain([tx, 'access',
|
|
1040
|
+
if (_optionalChain([tx, 'access', _36 => _36.data, 'optionalAccess', _37 => _37.calldata]) && typeof tx.data.calldata === "string") {
|
|
1027
1041
|
tx.data.calldata = {
|
|
1028
1042
|
base64: tx.data.calldata,
|
|
1029
1043
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -1054,7 +1068,7 @@ var receiptActions = (client, publicClient) => ({
|
|
|
1054
1068
|
const requestedStatus = _chunkW4V73RPNcjs.transactionsStatusNameToNumber[status];
|
|
1055
1069
|
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && _chunkW4V73RPNcjs.isDecidedState.call(void 0, transactionStatusString)) {
|
|
1056
1070
|
let finalTransaction = transaction;
|
|
1057
|
-
if (client.chain.id ===
|
|
1071
|
+
if (client.chain.id === _chunkSC2VXHL3cjs.localnet.id) {
|
|
1058
1072
|
finalTransaction = decodeLocalnetTransaction(transaction);
|
|
1059
1073
|
}
|
|
1060
1074
|
if (!fullTransaction) {
|
|
@@ -1085,8 +1099,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1085
1099
|
return decodeLocalnetTransaction(transaction2);
|
|
1086
1100
|
}
|
|
1087
1101
|
const transaction = await publicClient.readContract({
|
|
1088
|
-
address: _optionalChain([client, 'access',
|
|
1089
|
-
abi: _optionalChain([client, 'access',
|
|
1102
|
+
address: _optionalChain([client, 'access', _38 => _38.chain, 'access', _39 => _39.consensusDataContract, 'optionalAccess', _40 => _40.address]),
|
|
1103
|
+
abi: _optionalChain([client, 'access', _41 => _41.chain, 'access', _42 => _42.consensusDataContract, 'optionalAccess', _43 => _43.abi]),
|
|
1090
1104
|
functionName: "getTransactionData",
|
|
1091
1105
|
args: [
|
|
1092
1106
|
hash,
|
|
@@ -1098,7 +1112,7 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1098
1112
|
},
|
|
1099
1113
|
estimateTransactionGas: async (transactionParams) => {
|
|
1100
1114
|
const formattedParams = {
|
|
1101
|
-
from: transactionParams.from || _optionalChain([client, 'access',
|
|
1115
|
+
from: transactionParams.from || _optionalChain([client, 'access', _44 => _44.account, 'optionalAccess', _45 => _45.address]),
|
|
1102
1116
|
to: transactionParams.to,
|
|
1103
1117
|
data: transactionParams.data || "0x",
|
|
1104
1118
|
value: transactionParams.value ? `0x${transactionParams.value.toString(16)}` : "0x0"
|
|
@@ -1119,9 +1133,9 @@ var snapID = {
|
|
|
1119
1133
|
|
|
1120
1134
|
// src/wallet/connect.ts
|
|
1121
1135
|
var networks = {
|
|
1122
|
-
localnet:
|
|
1123
|
-
studionet:
|
|
1124
|
-
testnetAsimov:
|
|
1136
|
+
localnet: _chunkSC2VXHL3cjs.localnet,
|
|
1137
|
+
studionet: _chunkSC2VXHL3cjs.studionet,
|
|
1138
|
+
testnetAsimov: _chunkSC2VXHL3cjs.testnetAsimov
|
|
1125
1139
|
};
|
|
1126
1140
|
var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
1127
1141
|
if (!window.ethereum) {
|
|
@@ -1140,7 +1154,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
1140
1154
|
chainName: selectedNetwork.name,
|
|
1141
1155
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
1142
1156
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
1143
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
1157
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _46 => _46.blockExplorers, 'optionalAccess', _47 => _47.default, 'access', _48 => _48.url])]
|
|
1144
1158
|
};
|
|
1145
1159
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
1146
1160
|
if (currentChainId !== chainIdHex) {
|
|
@@ -1174,10 +1188,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1174
1188
|
}
|
|
1175
1189
|
const isFlask = async () => {
|
|
1176
1190
|
try {
|
|
1177
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
1191
|
+
const clientVersion = await _optionalChain([window, 'access', _49 => _49.ethereum, 'optionalAccess', _50 => _50.request, 'call', _51 => _51({
|
|
1178
1192
|
method: "web3_clientVersion"
|
|
1179
1193
|
})]);
|
|
1180
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
1194
|
+
return _optionalChain([clientVersion, 'optionalAccess', _52 => _52.includes, 'call', _53 => _53("flask")]);
|
|
1181
1195
|
} catch (error) {
|
|
1182
1196
|
console.error("Error detecting Flask:", error);
|
|
1183
1197
|
return false;
|
|
@@ -1185,7 +1199,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1185
1199
|
};
|
|
1186
1200
|
const installedSnaps = async () => {
|
|
1187
1201
|
try {
|
|
1188
|
-
return await _optionalChain([window, 'access',
|
|
1202
|
+
return await _optionalChain([window, 'access', _54 => _54.ethereum, 'optionalAccess', _55 => _55.request, 'call', _56 => _56({
|
|
1189
1203
|
method: "wallet_getSnaps"
|
|
1190
1204
|
})]);
|
|
1191
1205
|
} catch (error) {
|
|
@@ -1237,7 +1251,7 @@ function formatStakingAmount(amount) {
|
|
|
1237
1251
|
// src/staking/actions.ts
|
|
1238
1252
|
var FALLBACK_GAS = 1000000n;
|
|
1239
1253
|
var GAS_BUFFER_MULTIPLIER = 2n;
|
|
1240
|
-
var COMBINED_ERROR_ABI = [...
|
|
1254
|
+
var COMBINED_ERROR_ABI = [..._chunkSC2VXHL3cjs.STAKING_ABI, ..._chunkSC2VXHL3cjs.VALIDATOR_WALLET_ABI];
|
|
1241
1255
|
function extractRevertReason(err) {
|
|
1242
1256
|
if (err instanceof _viem.BaseError) {
|
|
1243
1257
|
const rawError = err.walk((e) => e instanceof _viem.RawContractError);
|
|
@@ -1272,7 +1286,7 @@ function extractRevertReason(err) {
|
|
|
1272
1286
|
}
|
|
1273
1287
|
const revertError = err.walk((e) => e instanceof _viem.ContractFunctionRevertedError);
|
|
1274
1288
|
if (revertError instanceof _viem.ContractFunctionRevertedError) {
|
|
1275
|
-
if (_optionalChain([revertError, 'access',
|
|
1289
|
+
if (_optionalChain([revertError, 'access', _57 => _57.data, 'optionalAccess', _58 => _58.errorName])) {
|
|
1276
1290
|
return revertError.data.errorName;
|
|
1277
1291
|
}
|
|
1278
1292
|
return revertError.reason || "Unknown reason";
|
|
@@ -1360,7 +1374,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1360
1374
|
};
|
|
1361
1375
|
const getStakingAddress = () => {
|
|
1362
1376
|
const stakingConfig = client.chain.stakingContract;
|
|
1363
|
-
if (!_optionalChain([stakingConfig, 'optionalAccess',
|
|
1377
|
+
if (!_optionalChain([stakingConfig, 'optionalAccess', _59 => _59.address]) || stakingConfig.address === "0x0000000000000000000000000000000000000000") {
|
|
1364
1378
|
throw new Error("Staking is not supported on studio-based networks. Use testnet-asimov for staking operations.");
|
|
1365
1379
|
}
|
|
1366
1380
|
return stakingConfig.address;
|
|
@@ -1369,7 +1383,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1369
1383
|
const address = getStakingAddress();
|
|
1370
1384
|
return _viem.getContract.call(void 0, {
|
|
1371
1385
|
address,
|
|
1372
|
-
abi:
|
|
1386
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1373
1387
|
client: { public: publicClient, wallet: client }
|
|
1374
1388
|
});
|
|
1375
1389
|
};
|
|
@@ -1377,7 +1391,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1377
1391
|
const address = getStakingAddress();
|
|
1378
1392
|
return _viem.getContract.call(void 0, {
|
|
1379
1393
|
address,
|
|
1380
|
-
abi:
|
|
1394
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1381
1395
|
client: publicClient
|
|
1382
1396
|
});
|
|
1383
1397
|
};
|
|
@@ -1386,11 +1400,11 @@ var stakingActions = (client, publicClient) => {
|
|
|
1386
1400
|
const amount = parseStakingAmount(options.amount);
|
|
1387
1401
|
const stakingAddress = getStakingAddress();
|
|
1388
1402
|
const data = options.operator ? _viem.encodeFunctionData.call(void 0, {
|
|
1389
|
-
abi:
|
|
1403
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1390
1404
|
functionName: "validatorJoin",
|
|
1391
1405
|
args: [options.operator]
|
|
1392
1406
|
}) : _viem.encodeFunctionData.call(void 0, {
|
|
1393
|
-
abi:
|
|
1407
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1394
1408
|
functionName: "validatorJoin"
|
|
1395
1409
|
});
|
|
1396
1410
|
const result = await executeWrite({ to: stakingAddress, data, value: amount });
|
|
@@ -1399,7 +1413,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1399
1413
|
let eventFound = false;
|
|
1400
1414
|
for (const log of receipt.logs) {
|
|
1401
1415
|
try {
|
|
1402
|
-
const decoded = _viem.decodeEventLog.call(void 0, { abi:
|
|
1416
|
+
const decoded = _viem.decodeEventLog.call(void 0, { abi: _chunkSC2VXHL3cjs.STAKING_ABI, data: log.data, topics: log.topics });
|
|
1403
1417
|
if (decoded.eventName === "ValidatorJoin") {
|
|
1404
1418
|
validatorWallet = decoded.args.validator;
|
|
1405
1419
|
eventFound = true;
|
|
@@ -1426,7 +1440,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1426
1440
|
validatorDeposit: async (options) => {
|
|
1427
1441
|
const amount = parseStakingAmount(options.amount);
|
|
1428
1442
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1429
|
-
abi:
|
|
1443
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1430
1444
|
functionName: "validatorDeposit"
|
|
1431
1445
|
});
|
|
1432
1446
|
return executeWrite({ to: getStakingAddress(), data, value: amount });
|
|
@@ -1434,19 +1448,19 @@ var stakingActions = (client, publicClient) => {
|
|
|
1434
1448
|
validatorExit: async (options) => {
|
|
1435
1449
|
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1436
1450
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1437
|
-
abi:
|
|
1451
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1438
1452
|
functionName: "validatorExit",
|
|
1439
1453
|
args: [shares]
|
|
1440
1454
|
});
|
|
1441
1455
|
return executeWrite({ to: getStakingAddress(), data });
|
|
1442
1456
|
},
|
|
1443
1457
|
validatorClaim: async (options) => {
|
|
1444
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1458
|
+
if (!_optionalChain([options, 'optionalAccess', _60 => _60.validator]) && !client.account) {
|
|
1445
1459
|
throw new Error("Either provide validator address or initialize client with an account");
|
|
1446
1460
|
}
|
|
1447
|
-
const validatorAddress = _optionalChain([options, 'optionalAccess',
|
|
1461
|
+
const validatorAddress = _optionalChain([options, 'optionalAccess', _61 => _61.validator]) || client.account.address;
|
|
1448
1462
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1449
|
-
abi:
|
|
1463
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1450
1464
|
functionName: "validatorClaim",
|
|
1451
1465
|
args: [validatorAddress]
|
|
1452
1466
|
});
|
|
@@ -1455,7 +1469,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1455
1469
|
},
|
|
1456
1470
|
validatorPrime: async (options) => {
|
|
1457
1471
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1458
|
-
abi:
|
|
1472
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1459
1473
|
functionName: "validatorPrime",
|
|
1460
1474
|
args: [options.validator]
|
|
1461
1475
|
});
|
|
@@ -1463,7 +1477,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1463
1477
|
},
|
|
1464
1478
|
setOperator: async (options) => {
|
|
1465
1479
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1466
|
-
abi:
|
|
1480
|
+
abi: _chunkSC2VXHL3cjs.VALIDATOR_WALLET_ABI,
|
|
1467
1481
|
functionName: "setOperator",
|
|
1468
1482
|
args: [options.operator]
|
|
1469
1483
|
});
|
|
@@ -1479,7 +1493,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1479
1493
|
}
|
|
1480
1494
|
}
|
|
1481
1495
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1482
|
-
abi:
|
|
1496
|
+
abi: _chunkSC2VXHL3cjs.VALIDATOR_WALLET_ABI,
|
|
1483
1497
|
functionName: "setIdentity",
|
|
1484
1498
|
args: [
|
|
1485
1499
|
options.moniker,
|
|
@@ -1498,7 +1512,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1498
1512
|
delegatorJoin: async (options) => {
|
|
1499
1513
|
const amount = parseStakingAmount(options.amount);
|
|
1500
1514
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1501
|
-
abi:
|
|
1515
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1502
1516
|
functionName: "delegatorJoin",
|
|
1503
1517
|
args: [options.validator]
|
|
1504
1518
|
});
|
|
@@ -1514,7 +1528,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1514
1528
|
delegatorExit: async (options) => {
|
|
1515
1529
|
const shares = typeof options.shares === "string" ? BigInt(options.shares) : options.shares;
|
|
1516
1530
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1517
|
-
abi:
|
|
1531
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1518
1532
|
functionName: "delegatorExit",
|
|
1519
1533
|
args: [options.validator, shares]
|
|
1520
1534
|
});
|
|
@@ -1526,7 +1540,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1526
1540
|
}
|
|
1527
1541
|
const delegatorAddress = options.delegator || client.account.address;
|
|
1528
1542
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1529
|
-
abi:
|
|
1543
|
+
abi: _chunkSC2VXHL3cjs.STAKING_ABI,
|
|
1530
1544
|
functionName: "delegatorClaim",
|
|
1531
1545
|
args: [delegatorAddress, options.validator]
|
|
1532
1546
|
});
|
|
@@ -1544,7 +1558,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1544
1558
|
}
|
|
1545
1559
|
const walletContract = _viem.getContract.call(void 0, {
|
|
1546
1560
|
address: validator,
|
|
1547
|
-
abi:
|
|
1561
|
+
abi: _chunkSC2VXHL3cjs.VALIDATOR_WALLET_ABI,
|
|
1548
1562
|
client: publicClient
|
|
1549
1563
|
});
|
|
1550
1564
|
const [view, owner, operator, identityRaw, currentEpoch] = await Promise.all([
|
|
@@ -1672,6 +1686,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1672
1686
|
const contract = getReadOnlyStakingContract();
|
|
1673
1687
|
const [
|
|
1674
1688
|
epoch,
|
|
1689
|
+
finalized,
|
|
1675
1690
|
validatorMinStake,
|
|
1676
1691
|
delegatorMinStake,
|
|
1677
1692
|
activeCount,
|
|
@@ -1681,6 +1696,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1681
1696
|
epochEven
|
|
1682
1697
|
] = await Promise.all([
|
|
1683
1698
|
contract.read.epoch(),
|
|
1699
|
+
contract.read.finalized(),
|
|
1684
1700
|
contract.read.validatorMinStake(),
|
|
1685
1701
|
contract.read.delegatorMinStake(),
|
|
1686
1702
|
contract.read.activeValidatorsCount(),
|
|
@@ -1690,8 +1706,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1690
1706
|
contract.read.epochEven()
|
|
1691
1707
|
]);
|
|
1692
1708
|
const currentEpochData = epoch % 2n === 0n ? epochEven : epochOdd;
|
|
1693
|
-
const
|
|
1694
|
-
const currentEpochEnd = currentEpochData.end > 0n ? new Date(Number(currentEpochData.end) * 1e3) : null;
|
|
1709
|
+
const currentEpochEnd = currentEpochData.end > 0n;
|
|
1695
1710
|
let nextEpochEstimate = null;
|
|
1696
1711
|
if (!currentEpochEnd) {
|
|
1697
1712
|
const duration = epoch === 0n ? epochZeroMinDuration : epochMinDuration;
|
|
@@ -1700,20 +1715,42 @@ var stakingActions = (client, publicClient) => {
|
|
|
1700
1715
|
}
|
|
1701
1716
|
return {
|
|
1702
1717
|
currentEpoch: epoch,
|
|
1718
|
+
lastFinalizedEpoch: finalized,
|
|
1703
1719
|
validatorMinStake: formatStakingAmount(validatorMinStake),
|
|
1704
1720
|
validatorMinStakeRaw: validatorMinStake,
|
|
1705
1721
|
delegatorMinStake: formatStakingAmount(delegatorMinStake),
|
|
1706
1722
|
delegatorMinStakeRaw: delegatorMinStake,
|
|
1707
1723
|
activeValidatorsCount: activeCount,
|
|
1708
1724
|
epochMinDuration,
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1725
|
+
nextEpochEstimate
|
|
1726
|
+
};
|
|
1727
|
+
},
|
|
1728
|
+
getEpochData: async (epochNumber) => {
|
|
1729
|
+
const contract = getReadOnlyStakingContract();
|
|
1730
|
+
const [currentEpoch, epochOdd, epochEven] = await Promise.all([
|
|
1731
|
+
contract.read.epoch(),
|
|
1732
|
+
contract.read.epochOdd(),
|
|
1733
|
+
contract.read.epochEven()
|
|
1734
|
+
]);
|
|
1735
|
+
if (epochNumber > currentEpoch) {
|
|
1736
|
+
throw new Error(`Epoch ${epochNumber} has not started yet (current: ${currentEpoch})`);
|
|
1737
|
+
}
|
|
1738
|
+
if (epochNumber < currentEpoch - 1n && currentEpoch > 0n) {
|
|
1739
|
+
throw new Error(`Epoch ${epochNumber} data no longer available (only current and previous epoch stored)`);
|
|
1740
|
+
}
|
|
1741
|
+
const epochData = epochNumber % 2n === 0n ? epochEven : epochOdd;
|
|
1742
|
+
return {
|
|
1743
|
+
start: epochData.start,
|
|
1744
|
+
end: epochData.end,
|
|
1745
|
+
inflation: epochData.inflation,
|
|
1746
|
+
weight: epochData.weight,
|
|
1747
|
+
weightDeposit: epochData.weightDeposit,
|
|
1748
|
+
weightWithdrawal: epochData.weightWithdrawal,
|
|
1749
|
+
vcount: epochData.vcount,
|
|
1750
|
+
claimed: epochData.claimed,
|
|
1751
|
+
stakeDeposit: epochData.stakeDeposit,
|
|
1752
|
+
stakeWithdrawal: epochData.stakeWithdrawal,
|
|
1753
|
+
slashed: epochData.slashed
|
|
1717
1754
|
};
|
|
1718
1755
|
},
|
|
1719
1756
|
getActiveValidators: async () => {
|
|
@@ -1747,6 +1784,11 @@ var stakingActions = (client, publicClient) => {
|
|
|
1747
1784
|
permanentlyBanned: v.permanentlyBanned
|
|
1748
1785
|
}));
|
|
1749
1786
|
},
|
|
1787
|
+
getSlashingAddress: async () => {
|
|
1788
|
+
const contract = getReadOnlyStakingContract();
|
|
1789
|
+
const externalContracts = await contract.read.contracts();
|
|
1790
|
+
return externalContracts[4];
|
|
1791
|
+
},
|
|
1750
1792
|
getStakingContract,
|
|
1751
1793
|
parseStakingAmount,
|
|
1752
1794
|
formatStakingAmount
|
|
@@ -1757,10 +1799,10 @@ var stakingActions = (client, publicClient) => {
|
|
|
1757
1799
|
function chainActions(client) {
|
|
1758
1800
|
return {
|
|
1759
1801
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
1760
|
-
if (_optionalChain([client, 'access',
|
|
1802
|
+
if (_optionalChain([client, 'access', _62 => _62.chain, 'optionalAccess', _63 => _63.id]) === _chunkSC2VXHL3cjs.testnetAsimov.id) {
|
|
1761
1803
|
return;
|
|
1762
1804
|
}
|
|
1763
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
1805
|
+
if (!forceReset && _optionalChain([client, 'access', _64 => _64.chain, 'access', _65 => _65.consensusMainContract, 'optionalAccess', _66 => _66.address]) && _optionalChain([client, 'access', _67 => _67.chain, 'access', _68 => _68.consensusMainContract, 'optionalAccess', _69 => _69.abi])) {
|
|
1764
1806
|
return;
|
|
1765
1807
|
}
|
|
1766
1808
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -1785,7 +1827,7 @@ function chainActions(client) {
|
|
|
1785
1827
|
}
|
|
1786
1828
|
|
|
1787
1829
|
// src/client/client.ts
|
|
1788
|
-
var getCustomTransportConfig = (config) => {
|
|
1830
|
+
var getCustomTransportConfig = (config, chainConfig) => {
|
|
1789
1831
|
const isAddress = typeof config.account !== "object";
|
|
1790
1832
|
return {
|
|
1791
1833
|
async request({ method, params = [] }) {
|
|
@@ -1801,11 +1843,8 @@ var getCustomTransportConfig = (config) => {
|
|
|
1801
1843
|
}
|
|
1802
1844
|
}
|
|
1803
1845
|
{
|
|
1804
|
-
if (!config.chain) {
|
|
1805
|
-
throw new Error("Chain is not set");
|
|
1806
|
-
}
|
|
1807
1846
|
try {
|
|
1808
|
-
const response = await fetch(
|
|
1847
|
+
const response = await fetch(chainConfig.rpcUrls.default.http[0], {
|
|
1809
1848
|
method: "POST",
|
|
1810
1849
|
headers: {
|
|
1811
1850
|
"Content-Type": "application/json"
|
|
@@ -1830,12 +1869,12 @@ var getCustomTransportConfig = (config) => {
|
|
|
1830
1869
|
}
|
|
1831
1870
|
};
|
|
1832
1871
|
};
|
|
1833
|
-
var createClient = (config = { chain:
|
|
1834
|
-
const chainConfig = config.chain ||
|
|
1872
|
+
var createClient = (config = { chain: _chunkSC2VXHL3cjs.localnet }) => {
|
|
1873
|
+
const chainConfig = config.chain || _chunkSC2VXHL3cjs.localnet;
|
|
1835
1874
|
if (config.endpoint) {
|
|
1836
1875
|
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
1837
1876
|
}
|
|
1838
|
-
const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config), { retryCount: 0, retryDelay: 0 });
|
|
1877
|
+
const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config, chainConfig), { retryCount: 0, retryDelay: 0 });
|
|
1839
1878
|
const publicClient = createPublicClient(chainConfig, customTransport).extend(
|
|
1840
1879
|
_viem.publicActions
|
|
1841
1880
|
);
|
|
@@ -1892,4 +1931,4 @@ var createAccount = (accountPrivateKey) => {
|
|
|
1892
1931
|
|
|
1893
1932
|
|
|
1894
1933
|
|
|
1895
|
-
exports.abi = abi_exports; exports.chains =
|
|
1934
|
+
exports.abi = abi_exports; exports.chains = _chunkSC2VXHL3cjs.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.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address, Hex } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-B7B7UXdn.cjs';
|
|
4
|
-
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement, S as STAKING_ABI, V as VALIDATOR_WALLET_ABI } from './index-
|
|
4
|
+
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement, S as STAKING_ABI, V as VALIDATOR_WALLET_ABI } from './index-D9ONjYgl.cjs';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_types_authorization from 'viem/_types/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address, Hex } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-B7B7UXdn.js';
|
|
4
|
-
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement, S as STAKING_ABI, V as VALIDATOR_WALLET_ABI } from './index-
|
|
4
|
+
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement, S as STAKING_ABI, V as VALIDATOR_WALLET_ABI } from './index-ZDqJWXj0.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_types_authorization from 'viem/_types/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|