genlayer-js 0.18.14 → 0.19.1
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/{index-DsN7LGHA.d.cts → index-CYszVbTS.d.cts} +2 -2
- package/dist/{index-sw3NAvBf.d.ts → index-CbVqYeWa.d.ts} +2 -2
- package/dist/index.cjs +195 -48
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +172 -25
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -276,7 +276,7 @@ interface ContractMethod extends ContractMethodBase {
|
|
|
276
276
|
}
|
|
277
277
|
type ContractSchema = {
|
|
278
278
|
ctor: ContractMethodBase;
|
|
279
|
-
methods: ContractMethod
|
|
279
|
+
methods: Record<string, ContractMethod>;
|
|
280
280
|
};
|
|
281
281
|
|
|
282
282
|
type Network = "localnet" | "studionet" | "testnetAsimov" | "mainnet";
|
|
@@ -2836,4 +2836,4 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
2836
2836
|
}) => Promise<any>;
|
|
2837
2837
|
} & StakingActions;
|
|
2838
2838
|
|
|
2839
|
-
export { type ValidatorPrimeOptions as $, type ValidatorView as A, type ValidatorIdentity as B, type CalldataEncodable as C, type DecodedDeployData as D, type ValidatorInfo as E, type PendingWithdrawal as F, type GenLayerClient as G, type Hash as H, type BannedValidatorInfo as I, type StakeInfo as J, type EpochData as K, type LeaderReceipt as L, type MethodDescription as M, type Network as N, type EpochInfo as O, type PendingDeposit as P, type StakingTransactionResult as Q, type ValidatorJoinResult as R, STAKING_ABI as S, type TransactionDataElement as T, type DelegatorJoinResult as U, VALIDATOR_WALLET_ABI as V, type WithdrawalCommit as W, type ValidatorJoinOptions as X, type ValidatorDepositOptions as Y, type ValidatorExitOptions as Z, type ValidatorClaimOptions as _, type DecodedCallData as a, type SetOperatorOptions as a0, type SetIdentityOptions as a1, type DelegatorJoinOptions as a2, type DelegatorExitOptions as a3, type DelegatorClaimOptions as a4, type StakingActions as a5, type GenLayerRawTransaction as b, type GenLayerTransaction as c,
|
|
2839
|
+
export { type ValidatorPrimeOptions as $, type ValidatorView as A, type ValidatorIdentity as B, type CalldataEncodable as C, type DecodedDeployData as D, type ValidatorInfo as E, type PendingWithdrawal as F, type GenLayerClient as G, type Hash as H, type BannedValidatorInfo as I, type StakeInfo as J, type EpochData as K, type LeaderReceipt as L, type MethodDescription as M, type Network as N, type EpochInfo as O, type PendingDeposit as P, type StakingTransactionResult as Q, type ValidatorJoinResult as R, STAKING_ABI as S, type TransactionDataElement as T, type DelegatorJoinResult as U, VALIDATOR_WALLET_ABI as V, type WithdrawalCommit as W, type ValidatorJoinOptions as X, type ValidatorDepositOptions as Y, type ValidatorExitOptions as Z, type ValidatorClaimOptions as _, type DecodedCallData as a, type SetOperatorOptions as a0, type SetIdentityOptions as a1, type DelegatorJoinOptions as a2, type DelegatorExitOptions as a3, type DelegatorClaimOptions as a4, type StakingActions as a5, type GenLayerRawTransaction as b, type GenLayerTransaction as c, type ContractSchema as d, CalldataAddress as e, type GenLayerMethod as f, type ContractParamsArraySchemaElement as g, type ContractParamsSchema as h, type ContractMethodBase as i, type ContractMethod as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, DECIDED_STATES as o, isDecidedState as p, transactionResultNumberToName as q, TransactionResultNameToNumber as r, VoteType as s, transactionsStatusNumberToName as t, voteTypeNameToNumber as u, voteTypeNumberToName as v, type TransactionType as w, TransactionHashVariant as x, type SnapSource as y, type StakingContract as z };
|
|
@@ -276,7 +276,7 @@ interface ContractMethod extends ContractMethodBase {
|
|
|
276
276
|
}
|
|
277
277
|
type ContractSchema = {
|
|
278
278
|
ctor: ContractMethodBase;
|
|
279
|
-
methods: ContractMethod
|
|
279
|
+
methods: Record<string, ContractMethod>;
|
|
280
280
|
};
|
|
281
281
|
|
|
282
282
|
type Network = "localnet" | "studionet" | "testnetAsimov" | "mainnet";
|
|
@@ -2836,4 +2836,4 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
2836
2836
|
}) => Promise<any>;
|
|
2837
2837
|
} & StakingActions;
|
|
2838
2838
|
|
|
2839
|
-
export { type ValidatorPrimeOptions as $, type ValidatorView as A, type ValidatorIdentity as B, type CalldataEncodable as C, type DecodedDeployData as D, type ValidatorInfo as E, type PendingWithdrawal as F, type GenLayerClient as G, type Hash as H, type BannedValidatorInfo as I, type StakeInfo as J, type EpochData as K, type LeaderReceipt as L, type MethodDescription as M, type Network as N, type EpochInfo as O, type PendingDeposit as P, type StakingTransactionResult as Q, type ValidatorJoinResult as R, STAKING_ABI as S, type TransactionDataElement as T, type DelegatorJoinResult as U, VALIDATOR_WALLET_ABI as V, type WithdrawalCommit as W, type ValidatorJoinOptions as X, type ValidatorDepositOptions as Y, type ValidatorExitOptions as Z, type ValidatorClaimOptions as _, type DecodedCallData as a, type SetOperatorOptions as a0, type SetIdentityOptions as a1, type DelegatorJoinOptions as a2, type DelegatorExitOptions as a3, type DelegatorClaimOptions as a4, type StakingActions as a5, type GenLayerRawTransaction as b, type GenLayerTransaction as c,
|
|
2839
|
+
export { type ValidatorPrimeOptions as $, type ValidatorView as A, type ValidatorIdentity as B, type CalldataEncodable as C, type DecodedDeployData as D, type ValidatorInfo as E, type PendingWithdrawal as F, type GenLayerClient as G, type Hash as H, type BannedValidatorInfo as I, type StakeInfo as J, type EpochData as K, type LeaderReceipt as L, type MethodDescription as M, type Network as N, type EpochInfo as O, type PendingDeposit as P, type StakingTransactionResult as Q, type ValidatorJoinResult as R, STAKING_ABI as S, type TransactionDataElement as T, type DelegatorJoinResult as U, VALIDATOR_WALLET_ABI as V, type WithdrawalCommit as W, type ValidatorJoinOptions as X, type ValidatorDepositOptions as Y, type ValidatorExitOptions as Z, type ValidatorClaimOptions as _, type DecodedCallData as a, type SetOperatorOptions as a0, type SetIdentityOptions as a1, type DelegatorJoinOptions as a2, type DelegatorExitOptions as a3, type DelegatorClaimOptions as a4, type StakingActions as a5, type GenLayerRawTransaction as b, type GenLayerTransaction as c, type ContractSchema as d, CalldataAddress as e, type GenLayerMethod as f, type ContractParamsArraySchemaElement as g, type ContractParamsSchema as h, type ContractMethodBase as i, type ContractMethod as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, DECIDED_STATES as o, isDecidedState as p, transactionResultNumberToName as q, TransactionResultNameToNumber as r, VoteType as s, transactionsStatusNumberToName as t, voteTypeNameToNumber as u, voteTypeNumberToName as v, type TransactionType as w, TransactionHashVariant as x, type SnapSource as y, type StakingContract as z };
|
package/dist/index.cjs
CHANGED
|
@@ -624,6 +624,7 @@ var contractActions = (client, publicClient) => {
|
|
|
624
624
|
leaderOnly = false,
|
|
625
625
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
626
626
|
} = args;
|
|
627
|
+
await client.initializeConsensusSmartContract();
|
|
627
628
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
628
629
|
const serializedData = serialize(data);
|
|
629
630
|
const senderAccount = account || client.account;
|
|
@@ -651,6 +652,7 @@ var contractActions = (client, publicClient) => {
|
|
|
651
652
|
leaderOnly = false,
|
|
652
653
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
653
654
|
} = args;
|
|
655
|
+
await client.initializeConsensusSmartContract();
|
|
654
656
|
const data = [
|
|
655
657
|
code,
|
|
656
658
|
encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
|
|
@@ -693,6 +695,50 @@ var validateAccount = (Account4) => {
|
|
|
693
695
|
}
|
|
694
696
|
return Account4;
|
|
695
697
|
};
|
|
698
|
+
var ADD_TRANSACTION_ABI_V5 = [
|
|
699
|
+
{
|
|
700
|
+
type: "function",
|
|
701
|
+
name: "addTransaction",
|
|
702
|
+
stateMutability: "nonpayable",
|
|
703
|
+
inputs: [
|
|
704
|
+
{ name: "_sender", type: "address" },
|
|
705
|
+
{ name: "_recipient", type: "address" },
|
|
706
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
707
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
708
|
+
{ name: "_txData", type: "bytes" }
|
|
709
|
+
],
|
|
710
|
+
outputs: []
|
|
711
|
+
}
|
|
712
|
+
];
|
|
713
|
+
var ADD_TRANSACTION_ABI_V6 = [
|
|
714
|
+
{
|
|
715
|
+
type: "function",
|
|
716
|
+
name: "addTransaction",
|
|
717
|
+
stateMutability: "nonpayable",
|
|
718
|
+
inputs: [
|
|
719
|
+
{ name: "_sender", type: "address" },
|
|
720
|
+
{ name: "_recipient", type: "address" },
|
|
721
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
722
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
723
|
+
{ name: "_txData", type: "bytes" },
|
|
724
|
+
{ name: "_validUntil", type: "uint256" }
|
|
725
|
+
],
|
|
726
|
+
outputs: []
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
var getAddTransactionInputCount = (abi) => {
|
|
730
|
+
if (!abi || !Array.isArray(abi)) {
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
const addTransactionFunction = abi.find((item) => {
|
|
734
|
+
if (!item || typeof item !== "object") {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const candidate = item;
|
|
738
|
+
return candidate.type === "function" && candidate.name === "addTransaction";
|
|
739
|
+
});
|
|
740
|
+
return Array.isArray(_optionalChain([addTransactionFunction, 'optionalAccess', _11 => _11.inputs])) ? addTransactionFunction.inputs.length : 0;
|
|
741
|
+
};
|
|
696
742
|
var _encodeAddTransactionData = ({
|
|
697
743
|
client,
|
|
698
744
|
senderAccount,
|
|
@@ -701,16 +747,24 @@ var _encodeAddTransactionData = ({
|
|
|
701
747
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
702
748
|
}) => {
|
|
703
749
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
750
|
+
const addTransactionArgs = [
|
|
751
|
+
validatedSenderAccount.address,
|
|
752
|
+
recipient,
|
|
753
|
+
client.chain.defaultNumberOfInitialValidators,
|
|
754
|
+
consensusMaxRotations,
|
|
755
|
+
data
|
|
756
|
+
];
|
|
757
|
+
if (getAddTransactionInputCount(_optionalChain([client, 'access', _12 => _12.chain, 'access', _13 => _13.consensusMainContract, 'optionalAccess', _14 => _14.abi])) >= 6) {
|
|
758
|
+
return _viem.encodeFunctionData.call(void 0, {
|
|
759
|
+
abi: ADD_TRANSACTION_ABI_V6,
|
|
760
|
+
functionName: "addTransaction",
|
|
761
|
+
args: [...addTransactionArgs, 0n]
|
|
762
|
+
});
|
|
763
|
+
}
|
|
704
764
|
return _viem.encodeFunctionData.call(void 0, {
|
|
705
|
-
abi:
|
|
765
|
+
abi: ADD_TRANSACTION_ABI_V5,
|
|
706
766
|
functionName: "addTransaction",
|
|
707
|
-
args:
|
|
708
|
-
validatedSenderAccount.address,
|
|
709
|
-
recipient,
|
|
710
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
711
|
-
consensusMaxRotations,
|
|
712
|
-
data
|
|
713
|
-
]
|
|
767
|
+
args: addTransactionArgs
|
|
714
768
|
});
|
|
715
769
|
};
|
|
716
770
|
var _encodeSubmitAppealData = ({
|
|
@@ -718,7 +772,7 @@ var _encodeSubmitAppealData = ({
|
|
|
718
772
|
txId
|
|
719
773
|
}) => {
|
|
720
774
|
return _viem.encodeFunctionData.call(void 0, {
|
|
721
|
-
abi: _optionalChain([client, 'access',
|
|
775
|
+
abi: _optionalChain([client, 'access', _15 => _15.chain, 'access', _16 => _16.consensusMainContract, 'optionalAccess', _17 => _17.abi]),
|
|
722
776
|
functionName: "submitAppeal",
|
|
723
777
|
args: [txId]
|
|
724
778
|
});
|
|
@@ -730,7 +784,7 @@ var _sendTransaction = async ({
|
|
|
730
784
|
senderAccount,
|
|
731
785
|
value = 0n
|
|
732
786
|
}) => {
|
|
733
|
-
if (!_optionalChain([client, 'access',
|
|
787
|
+
if (!_optionalChain([client, 'access', _18 => _18.chain, 'access', _19 => _19.consensusMainContract, 'optionalAccess', _20 => _20.address])) {
|
|
734
788
|
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
735
789
|
}
|
|
736
790
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
@@ -739,7 +793,7 @@ var _sendTransaction = async ({
|
|
|
739
793
|
try {
|
|
740
794
|
estimatedGas = await client.estimateTransactionGas({
|
|
741
795
|
from: validatedSenderAccount.address,
|
|
742
|
-
to: _optionalChain([client, 'access',
|
|
796
|
+
to: _optionalChain([client, 'access', _21 => _21.chain, 'access', _22 => _22.consensusMainContract, 'optionalAccess', _23 => _23.address]),
|
|
743
797
|
data: encodedData,
|
|
744
798
|
value
|
|
745
799
|
});
|
|
@@ -747,8 +801,8 @@ var _sendTransaction = async ({
|
|
|
747
801
|
console.error("Gas estimation failed, using default 200_000:", err);
|
|
748
802
|
estimatedGas = 200000n;
|
|
749
803
|
}
|
|
750
|
-
if (_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
751
|
-
if (!_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
804
|
+
if (_optionalChain([validatedSenderAccount, 'optionalAccess', _24 => _24.type]) === "local") {
|
|
805
|
+
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _25 => _25.signTransaction])) {
|
|
752
806
|
throw new Error("Account does not support signTransaction");
|
|
753
807
|
}
|
|
754
808
|
const gasPriceHex = await client.request({
|
|
@@ -756,7 +810,7 @@ var _sendTransaction = async ({
|
|
|
756
810
|
});
|
|
757
811
|
const transactionRequest2 = {
|
|
758
812
|
account: validatedSenderAccount,
|
|
759
|
-
to: _optionalChain([client, 'access',
|
|
813
|
+
to: _optionalChain([client, 'access', _26 => _26.chain, 'access', _27 => _27.consensusMainContract, 'optionalAccess', _28 => _28.address]),
|
|
760
814
|
data: encodedData,
|
|
761
815
|
type: "legacy",
|
|
762
816
|
nonce: Number(nonce),
|
|
@@ -772,7 +826,7 @@ var _sendTransaction = async ({
|
|
|
772
826
|
throw new Error("Transaction reverted");
|
|
773
827
|
}
|
|
774
828
|
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
775
|
-
abi: _optionalChain([client, 'access',
|
|
829
|
+
abi: _optionalChain([client, 'access', _29 => _29.chain, 'access', _30 => _30.consensusMainContract, 'optionalAccess', _31 => _31.abi]),
|
|
776
830
|
eventName: "NewTransaction",
|
|
777
831
|
logs: receipt.logs
|
|
778
832
|
});
|
|
@@ -783,7 +837,7 @@ var _sendTransaction = async ({
|
|
|
783
837
|
}
|
|
784
838
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
785
839
|
account: validatedSenderAccount,
|
|
786
|
-
to: _optionalChain([client, 'access',
|
|
840
|
+
to: _optionalChain([client, 'access', _32 => _32.chain, 'access', _33 => _33.consensusMainContract, 'optionalAccess', _34 => _34.address]),
|
|
787
841
|
data: encodedData,
|
|
788
842
|
type: "legacy",
|
|
789
843
|
nonce: Number(nonce),
|
|
@@ -1007,7 +1061,7 @@ var simplifyTransactionReceipt = (tx) => {
|
|
|
1007
1061
|
var decodeLocalnetTransaction = (tx) => {
|
|
1008
1062
|
if (!tx.data) return tx;
|
|
1009
1063
|
try {
|
|
1010
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
1064
|
+
const leaderReceipt = _optionalChain([tx, 'access', _35 => _35.consensus_data, 'optionalAccess', _36 => _36.leader_receipt]);
|
|
1011
1065
|
if (leaderReceipt) {
|
|
1012
1066
|
const receipts = Array.isArray(leaderReceipt) ? leaderReceipt : [leaderReceipt];
|
|
1013
1067
|
receipts.forEach((receipt) => {
|
|
@@ -1038,7 +1092,7 @@ var decodeLocalnetTransaction = (tx) => {
|
|
|
1038
1092
|
}
|
|
1039
1093
|
});
|
|
1040
1094
|
}
|
|
1041
|
-
if (_optionalChain([tx, 'access',
|
|
1095
|
+
if (_optionalChain([tx, 'access', _37 => _37.data, 'optionalAccess', _38 => _38.calldata]) && typeof tx.data.calldata === "string") {
|
|
1042
1096
|
tx.data.calldata = {
|
|
1043
1097
|
base64: tx.data.calldata,
|
|
1044
1098
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -1100,8 +1154,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1100
1154
|
return decodeLocalnetTransaction(transaction2);
|
|
1101
1155
|
}
|
|
1102
1156
|
const transaction = await publicClient.readContract({
|
|
1103
|
-
address: _optionalChain([client, 'access',
|
|
1104
|
-
abi: _optionalChain([client, 'access',
|
|
1157
|
+
address: _optionalChain([client, 'access', _39 => _39.chain, 'access', _40 => _40.consensusDataContract, 'optionalAccess', _41 => _41.address]),
|
|
1158
|
+
abi: _optionalChain([client, 'access', _42 => _42.chain, 'access', _43 => _43.consensusDataContract, 'optionalAccess', _44 => _44.abi]),
|
|
1105
1159
|
functionName: "getTransactionData",
|
|
1106
1160
|
args: [
|
|
1107
1161
|
hash,
|
|
@@ -1113,7 +1167,7 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1113
1167
|
},
|
|
1114
1168
|
estimateTransactionGas: async (transactionParams) => {
|
|
1115
1169
|
const formattedParams = {
|
|
1116
|
-
from: transactionParams.from || _optionalChain([client, 'access',
|
|
1170
|
+
from: transactionParams.from || _optionalChain([client, 'access', _45 => _45.account, 'optionalAccess', _46 => _46.address]),
|
|
1117
1171
|
to: transactionParams.to,
|
|
1118
1172
|
data: transactionParams.data || "0x",
|
|
1119
1173
|
value: transactionParams.value ? `0x${transactionParams.value.toString(16)}` : "0x0"
|
|
@@ -1155,7 +1209,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
1155
1209
|
chainName: selectedNetwork.name,
|
|
1156
1210
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
1157
1211
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
1158
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
1212
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _47 => _47.blockExplorers, 'optionalAccess', _48 => _48.default, 'access', _49 => _49.url])]
|
|
1159
1213
|
};
|
|
1160
1214
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
1161
1215
|
if (currentChainId !== chainIdHex) {
|
|
@@ -1189,10 +1243,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1189
1243
|
}
|
|
1190
1244
|
const isFlask = async () => {
|
|
1191
1245
|
try {
|
|
1192
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
1246
|
+
const clientVersion = await _optionalChain([window, 'access', _50 => _50.ethereum, 'optionalAccess', _51 => _51.request, 'call', _52 => _52({
|
|
1193
1247
|
method: "web3_clientVersion"
|
|
1194
1248
|
})]);
|
|
1195
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
1249
|
+
return _optionalChain([clientVersion, 'optionalAccess', _53 => _53.includes, 'call', _54 => _54("flask")]);
|
|
1196
1250
|
} catch (error) {
|
|
1197
1251
|
console.error("Error detecting Flask:", error);
|
|
1198
1252
|
return false;
|
|
@@ -1200,7 +1254,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1200
1254
|
};
|
|
1201
1255
|
const installedSnaps = async () => {
|
|
1202
1256
|
try {
|
|
1203
|
-
return await _optionalChain([window, 'access',
|
|
1257
|
+
return await _optionalChain([window, 'access', _55 => _55.ethereum, 'optionalAccess', _56 => _56.request, 'call', _57 => _57({
|
|
1204
1258
|
method: "wallet_getSnaps"
|
|
1205
1259
|
})]);
|
|
1206
1260
|
} catch (error) {
|
|
@@ -1287,7 +1341,7 @@ function extractRevertReason(err) {
|
|
|
1287
1341
|
}
|
|
1288
1342
|
const revertError = err.walk((e) => e instanceof _viem.ContractFunctionRevertedError);
|
|
1289
1343
|
if (revertError instanceof _viem.ContractFunctionRevertedError) {
|
|
1290
|
-
if (_optionalChain([revertError, 'access',
|
|
1344
|
+
if (_optionalChain([revertError, 'access', _58 => _58.data, 'optionalAccess', _59 => _59.errorName])) {
|
|
1291
1345
|
return revertError.data.errorName;
|
|
1292
1346
|
}
|
|
1293
1347
|
return revertError.reason || "Unknown reason";
|
|
@@ -1375,7 +1429,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1375
1429
|
};
|
|
1376
1430
|
const getStakingAddress = () => {
|
|
1377
1431
|
const stakingConfig = client.chain.stakingContract;
|
|
1378
|
-
if (!_optionalChain([stakingConfig, 'optionalAccess',
|
|
1432
|
+
if (!_optionalChain([stakingConfig, 'optionalAccess', _60 => _60.address]) || stakingConfig.address === "0x0000000000000000000000000000000000000000") {
|
|
1379
1433
|
throw new Error("Staking is not supported on studio-based networks. Use testnet-asimov for staking operations.");
|
|
1380
1434
|
}
|
|
1381
1435
|
return stakingConfig.address;
|
|
@@ -1456,10 +1510,10 @@ var stakingActions = (client, publicClient) => {
|
|
|
1456
1510
|
return executeWrite({ to: getStakingAddress(), data });
|
|
1457
1511
|
},
|
|
1458
1512
|
validatorClaim: async (options) => {
|
|
1459
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1513
|
+
if (!_optionalChain([options, 'optionalAccess', _61 => _61.validator]) && !client.account) {
|
|
1460
1514
|
throw new Error("Either provide validator address or initialize client with an account");
|
|
1461
1515
|
}
|
|
1462
|
-
const validatorAddress = _optionalChain([options, 'optionalAccess',
|
|
1516
|
+
const validatorAddress = _optionalChain([options, 'optionalAccess', _62 => _62.validator]) || client.account.address;
|
|
1463
1517
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1464
1518
|
abi: _chunk5TKVNHAOcjs.STAKING_ABI,
|
|
1465
1519
|
functionName: "validatorClaim",
|
|
@@ -1800,29 +1854,43 @@ var stakingActions = (client, publicClient) => {
|
|
|
1800
1854
|
function chainActions(client) {
|
|
1801
1855
|
return {
|
|
1802
1856
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
1803
|
-
if (_optionalChain([client, 'access',
|
|
1857
|
+
if (_optionalChain([client, 'access', _63 => _63.chain, 'optionalAccess', _64 => _64.id]) === _chunk5TKVNHAOcjs.testnetAsimov.id) {
|
|
1804
1858
|
return;
|
|
1805
1859
|
}
|
|
1806
|
-
|
|
1860
|
+
const hasStaticConsensusContract = !!_optionalChain([client, 'access', _65 => _65.chain, 'access', _66 => _66.consensusMainContract, 'optionalAccess', _67 => _67.address]) && !!_optionalChain([client, 'access', _68 => _68.chain, 'access', _69 => _69.consensusMainContract, 'optionalAccess', _70 => _70.abi]);
|
|
1861
|
+
const isLocalOrStudioChain = _optionalChain([client, 'access', _71 => _71.chain, 'optionalAccess', _72 => _72.id]) === _chunk5TKVNHAOcjs.localnet.id || _optionalChain([client, 'access', _73 => _73.chain, 'optionalAccess', _74 => _74.id]) === _chunk5TKVNHAOcjs.studionet.id;
|
|
1862
|
+
if (!forceReset && hasStaticConsensusContract && !isLocalOrStudioChain) {
|
|
1807
1863
|
return;
|
|
1808
1864
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1865
|
+
try {
|
|
1866
|
+
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
1867
|
+
method: "POST",
|
|
1868
|
+
headers: {
|
|
1869
|
+
"Content-Type": "application/json"
|
|
1870
|
+
},
|
|
1871
|
+
body: JSON.stringify({
|
|
1872
|
+
jsonrpc: "2.0",
|
|
1873
|
+
id: Date.now(),
|
|
1874
|
+
method: "sim_getConsensusContract",
|
|
1875
|
+
params: ["ConsensusMain"]
|
|
1876
|
+
})
|
|
1877
|
+
});
|
|
1878
|
+
if (!contractsResponse.ok) {
|
|
1879
|
+
throw new Error("Failed to fetch ConsensusMain contract");
|
|
1880
|
+
}
|
|
1881
|
+
const consensusMainContract = await contractsResponse.json();
|
|
1882
|
+
if (_optionalChain([consensusMainContract, 'optionalAccess', _75 => _75.error]) || !_optionalChain([consensusMainContract, 'optionalAccess', _76 => _76.result, 'optionalAccess', _77 => _77.address]) || !_optionalChain([consensusMainContract, 'optionalAccess', _78 => _78.result, 'optionalAccess', _79 => _79.abi])) {
|
|
1883
|
+
throw new Error("ConsensusMain response did not include a valid contract");
|
|
1884
|
+
}
|
|
1885
|
+
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1886
|
+
client.chain.__consensusAbiFetchedFromRpc = true;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (hasStaticConsensusContract) {
|
|
1889
|
+
client.chain.__consensusAbiFetchedFromRpc = false;
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1823
1893
|
}
|
|
1824
|
-
const consensusMainContract = await contractsResponse.json();
|
|
1825
|
-
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1826
1894
|
}
|
|
1827
1895
|
};
|
|
1828
1896
|
}
|
|
@@ -1921,6 +1989,85 @@ var createAccount = (accountPrivateKey) => {
|
|
|
1921
1989
|
return account;
|
|
1922
1990
|
};
|
|
1923
1991
|
|
|
1992
|
+
// src/contracts/schema.ts
|
|
1993
|
+
function buildGenVmPositionalArgs(options) {
|
|
1994
|
+
const { schema, functionName, valuesByParamName, strictTypes = true } = options;
|
|
1995
|
+
const method = schema.methods[functionName];
|
|
1996
|
+
if (!method) {
|
|
1997
|
+
throw new Error(`GenVM schema missing method: ${functionName}`);
|
|
1998
|
+
}
|
|
1999
|
+
return method.params.map(([name, type], index) => {
|
|
2000
|
+
if (!(name in valuesByParamName)) {
|
|
2001
|
+
throw new Error(
|
|
2002
|
+
`Missing argument "${name}" for ${functionName} (index ${index})`
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
const value = valuesByParamName[name];
|
|
2006
|
+
if (strictTypes && !validateValueAgainstType(value, type)) {
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`Invalid argument "${name}" for ${functionName} (index ${index})`
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
return value;
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
function isPlainObject(value) {
|
|
2015
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Map);
|
|
2016
|
+
}
|
|
2017
|
+
function validateValueAgainstType(value, type) {
|
|
2018
|
+
if (type === "any") return true;
|
|
2019
|
+
if (type === "null") return value === null;
|
|
2020
|
+
if (type === "bool") return typeof value === "boolean";
|
|
2021
|
+
if (type === "string") return typeof value === "string";
|
|
2022
|
+
if (type === "bytes") {
|
|
2023
|
+
return typeof value === "string" || value instanceof Uint8Array;
|
|
2024
|
+
}
|
|
2025
|
+
if (type === "address") return typeof value === "string";
|
|
2026
|
+
if (type === "int") return typeof value === "number" || typeof value === "bigint";
|
|
2027
|
+
if (type === "array") return Array.isArray(value);
|
|
2028
|
+
if (type === "dict") return isPlainObject(value) || value instanceof Map;
|
|
2029
|
+
if (Array.isArray(type)) {
|
|
2030
|
+
if (!Array.isArray(value)) return false;
|
|
2031
|
+
if (type.length === 1 && typeof type[0] === "object" && type[0] !== null && "$rep" in type[0]) {
|
|
2032
|
+
const elementType = type[0].$rep;
|
|
2033
|
+
return value.every((v) => validateValueAgainstType(v, elementType));
|
|
2034
|
+
}
|
|
2035
|
+
return true;
|
|
2036
|
+
}
|
|
2037
|
+
if (isPlainObject(type)) {
|
|
2038
|
+
const orTypes = type.$or;
|
|
2039
|
+
if (Array.isArray(orTypes)) {
|
|
2040
|
+
return orTypes.some(
|
|
2041
|
+
(t) => validateValueAgainstType(value, t)
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
if ("$dict" in type) {
|
|
2045
|
+
const dictType = type.$dict;
|
|
2046
|
+
if (value instanceof Map) {
|
|
2047
|
+
for (const v of value.values()) {
|
|
2048
|
+
if (!validateValueAgainstType(v, dictType)) return false;
|
|
2049
|
+
}
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
if (!isPlainObject(value)) return false;
|
|
2053
|
+
return Object.values(value).every(
|
|
2054
|
+
(v) => validateValueAgainstType(v, dictType)
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
if (isPlainObject(value)) {
|
|
2058
|
+
return Object.entries(type).every(([key, keyType]) => {
|
|
2059
|
+
if (!(key in value)) return true;
|
|
2060
|
+
return validateValueAgainstType(
|
|
2061
|
+
value[key],
|
|
2062
|
+
keyType
|
|
2063
|
+
);
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
return true;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
|
|
1924
2071
|
|
|
1925
2072
|
|
|
1926
2073
|
|
|
@@ -1932,4 +2079,4 @@ var createAccount = (accountPrivateKey) => {
|
|
|
1932
2079
|
|
|
1933
2080
|
|
|
1934
2081
|
|
|
1935
|
-
exports.abi = abi_exports; exports.chains = _chunk5TKVNHAOcjs.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;
|
|
2082
|
+
exports.abi = abi_exports; exports.buildGenVmPositionalArgs = buildGenVmPositionalArgs; exports.chains = _chunk5TKVNHAOcjs.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, d as ContractSchema } from './index-CYszVbTS.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';
|
|
@@ -106,4 +106,11 @@ declare function parseStakingAmount(amount: string | bigint): bigint;
|
|
|
106
106
|
*/
|
|
107
107
|
declare function formatStakingAmount(amount: bigint): string;
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
declare function buildGenVmPositionalArgs(options: {
|
|
110
|
+
schema: ContractSchema;
|
|
111
|
+
functionName: string;
|
|
112
|
+
valuesByParamName: Record<string, unknown>;
|
|
113
|
+
strictTypes?: boolean;
|
|
114
|
+
}): unknown[];
|
|
115
|
+
|
|
116
|
+
export { index as abi, buildGenVmPositionalArgs, createAccount, createClient, decodeInputData, decodeLocalnetTransaction, decodeTransaction, formatStakingAmount, generatePrivateKey, parseStakingAmount, simplifyTransactionReceipt };
|
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, d as ContractSchema } from './index-CbVqYeWa.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';
|
|
@@ -106,4 +106,11 @@ declare function parseStakingAmount(amount: string | bigint): bigint;
|
|
|
106
106
|
*/
|
|
107
107
|
declare function formatStakingAmount(amount: bigint): string;
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
declare function buildGenVmPositionalArgs(options: {
|
|
110
|
+
schema: ContractSchema;
|
|
111
|
+
functionName: string;
|
|
112
|
+
valuesByParamName: Record<string, unknown>;
|
|
113
|
+
strictTypes?: boolean;
|
|
114
|
+
}): unknown[];
|
|
115
|
+
|
|
116
|
+
export { index as abi, buildGenVmPositionalArgs, createAccount, createClient, decodeInputData, decodeLocalnetTransaction, decodeTransaction, formatStakingAmount, generatePrivateKey, parseStakingAmount, simplifyTransactionReceipt };
|
package/dist/index.js
CHANGED
|
@@ -624,6 +624,7 @@ var contractActions = (client, publicClient) => {
|
|
|
624
624
|
leaderOnly = false,
|
|
625
625
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
626
626
|
} = args;
|
|
627
|
+
await client.initializeConsensusSmartContract();
|
|
627
628
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
628
629
|
const serializedData = serialize(data);
|
|
629
630
|
const senderAccount = account || client.account;
|
|
@@ -651,6 +652,7 @@ var contractActions = (client, publicClient) => {
|
|
|
651
652
|
leaderOnly = false,
|
|
652
653
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
653
654
|
} = args;
|
|
655
|
+
await client.initializeConsensusSmartContract();
|
|
654
656
|
const data = [
|
|
655
657
|
code,
|
|
656
658
|
encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
|
|
@@ -693,6 +695,50 @@ var validateAccount = (Account4) => {
|
|
|
693
695
|
}
|
|
694
696
|
return Account4;
|
|
695
697
|
};
|
|
698
|
+
var ADD_TRANSACTION_ABI_V5 = [
|
|
699
|
+
{
|
|
700
|
+
type: "function",
|
|
701
|
+
name: "addTransaction",
|
|
702
|
+
stateMutability: "nonpayable",
|
|
703
|
+
inputs: [
|
|
704
|
+
{ name: "_sender", type: "address" },
|
|
705
|
+
{ name: "_recipient", type: "address" },
|
|
706
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
707
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
708
|
+
{ name: "_txData", type: "bytes" }
|
|
709
|
+
],
|
|
710
|
+
outputs: []
|
|
711
|
+
}
|
|
712
|
+
];
|
|
713
|
+
var ADD_TRANSACTION_ABI_V6 = [
|
|
714
|
+
{
|
|
715
|
+
type: "function",
|
|
716
|
+
name: "addTransaction",
|
|
717
|
+
stateMutability: "nonpayable",
|
|
718
|
+
inputs: [
|
|
719
|
+
{ name: "_sender", type: "address" },
|
|
720
|
+
{ name: "_recipient", type: "address" },
|
|
721
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
722
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
723
|
+
{ name: "_txData", type: "bytes" },
|
|
724
|
+
{ name: "_validUntil", type: "uint256" }
|
|
725
|
+
],
|
|
726
|
+
outputs: []
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
var getAddTransactionInputCount = (abi) => {
|
|
730
|
+
if (!abi || !Array.isArray(abi)) {
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
const addTransactionFunction = abi.find((item) => {
|
|
734
|
+
if (!item || typeof item !== "object") {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const candidate = item;
|
|
738
|
+
return candidate.type === "function" && candidate.name === "addTransaction";
|
|
739
|
+
});
|
|
740
|
+
return Array.isArray(addTransactionFunction?.inputs) ? addTransactionFunction.inputs.length : 0;
|
|
741
|
+
};
|
|
696
742
|
var _encodeAddTransactionData = ({
|
|
697
743
|
client,
|
|
698
744
|
senderAccount,
|
|
@@ -701,16 +747,24 @@ var _encodeAddTransactionData = ({
|
|
|
701
747
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
702
748
|
}) => {
|
|
703
749
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
750
|
+
const addTransactionArgs = [
|
|
751
|
+
validatedSenderAccount.address,
|
|
752
|
+
recipient,
|
|
753
|
+
client.chain.defaultNumberOfInitialValidators,
|
|
754
|
+
consensusMaxRotations,
|
|
755
|
+
data
|
|
756
|
+
];
|
|
757
|
+
if (getAddTransactionInputCount(client.chain.consensusMainContract?.abi) >= 6) {
|
|
758
|
+
return encodeFunctionData({
|
|
759
|
+
abi: ADD_TRANSACTION_ABI_V6,
|
|
760
|
+
functionName: "addTransaction",
|
|
761
|
+
args: [...addTransactionArgs, 0n]
|
|
762
|
+
});
|
|
763
|
+
}
|
|
704
764
|
return encodeFunctionData({
|
|
705
|
-
abi:
|
|
765
|
+
abi: ADD_TRANSACTION_ABI_V5,
|
|
706
766
|
functionName: "addTransaction",
|
|
707
|
-
args:
|
|
708
|
-
validatedSenderAccount.address,
|
|
709
|
-
recipient,
|
|
710
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
711
|
-
consensusMaxRotations,
|
|
712
|
-
data
|
|
713
|
-
]
|
|
767
|
+
args: addTransactionArgs
|
|
714
768
|
});
|
|
715
769
|
};
|
|
716
770
|
var _encodeSubmitAppealData = ({
|
|
@@ -1803,26 +1857,40 @@ function chainActions(client) {
|
|
|
1803
1857
|
if (client.chain?.id === testnetAsimov.id) {
|
|
1804
1858
|
return;
|
|
1805
1859
|
}
|
|
1806
|
-
|
|
1860
|
+
const hasStaticConsensusContract = !!client.chain.consensusMainContract?.address && !!client.chain.consensusMainContract?.abi;
|
|
1861
|
+
const isLocalOrStudioChain = client.chain?.id === localnet.id || client.chain?.id === studionet.id;
|
|
1862
|
+
if (!forceReset && hasStaticConsensusContract && !isLocalOrStudioChain) {
|
|
1807
1863
|
return;
|
|
1808
1864
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1865
|
+
try {
|
|
1866
|
+
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
1867
|
+
method: "POST",
|
|
1868
|
+
headers: {
|
|
1869
|
+
"Content-Type": "application/json"
|
|
1870
|
+
},
|
|
1871
|
+
body: JSON.stringify({
|
|
1872
|
+
jsonrpc: "2.0",
|
|
1873
|
+
id: Date.now(),
|
|
1874
|
+
method: "sim_getConsensusContract",
|
|
1875
|
+
params: ["ConsensusMain"]
|
|
1876
|
+
})
|
|
1877
|
+
});
|
|
1878
|
+
if (!contractsResponse.ok) {
|
|
1879
|
+
throw new Error("Failed to fetch ConsensusMain contract");
|
|
1880
|
+
}
|
|
1881
|
+
const consensusMainContract = await contractsResponse.json();
|
|
1882
|
+
if (consensusMainContract?.error || !consensusMainContract?.result?.address || !consensusMainContract?.result?.abi) {
|
|
1883
|
+
throw new Error("ConsensusMain response did not include a valid contract");
|
|
1884
|
+
}
|
|
1885
|
+
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1886
|
+
client.chain.__consensusAbiFetchedFromRpc = true;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (hasStaticConsensusContract) {
|
|
1889
|
+
client.chain.__consensusAbiFetchedFromRpc = false;
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1823
1893
|
}
|
|
1824
|
-
const consensusMainContract = await contractsResponse.json();
|
|
1825
|
-
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1826
1894
|
}
|
|
1827
1895
|
};
|
|
1828
1896
|
}
|
|
@@ -1920,8 +1988,87 @@ var createAccount = (accountPrivateKey) => {
|
|
|
1920
1988
|
const account = privateKeyToAccount(privateKey);
|
|
1921
1989
|
return account;
|
|
1922
1990
|
};
|
|
1991
|
+
|
|
1992
|
+
// src/contracts/schema.ts
|
|
1993
|
+
function buildGenVmPositionalArgs(options) {
|
|
1994
|
+
const { schema, functionName, valuesByParamName, strictTypes = true } = options;
|
|
1995
|
+
const method = schema.methods[functionName];
|
|
1996
|
+
if (!method) {
|
|
1997
|
+
throw new Error(`GenVM schema missing method: ${functionName}`);
|
|
1998
|
+
}
|
|
1999
|
+
return method.params.map(([name, type], index) => {
|
|
2000
|
+
if (!(name in valuesByParamName)) {
|
|
2001
|
+
throw new Error(
|
|
2002
|
+
`Missing argument "${name}" for ${functionName} (index ${index})`
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
const value = valuesByParamName[name];
|
|
2006
|
+
if (strictTypes && !validateValueAgainstType(value, type)) {
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`Invalid argument "${name}" for ${functionName} (index ${index})`
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
return value;
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
function isPlainObject(value) {
|
|
2015
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Map);
|
|
2016
|
+
}
|
|
2017
|
+
function validateValueAgainstType(value, type) {
|
|
2018
|
+
if (type === "any") return true;
|
|
2019
|
+
if (type === "null") return value === null;
|
|
2020
|
+
if (type === "bool") return typeof value === "boolean";
|
|
2021
|
+
if (type === "string") return typeof value === "string";
|
|
2022
|
+
if (type === "bytes") {
|
|
2023
|
+
return typeof value === "string" || value instanceof Uint8Array;
|
|
2024
|
+
}
|
|
2025
|
+
if (type === "address") return typeof value === "string";
|
|
2026
|
+
if (type === "int") return typeof value === "number" || typeof value === "bigint";
|
|
2027
|
+
if (type === "array") return Array.isArray(value);
|
|
2028
|
+
if (type === "dict") return isPlainObject(value) || value instanceof Map;
|
|
2029
|
+
if (Array.isArray(type)) {
|
|
2030
|
+
if (!Array.isArray(value)) return false;
|
|
2031
|
+
if (type.length === 1 && typeof type[0] === "object" && type[0] !== null && "$rep" in type[0]) {
|
|
2032
|
+
const elementType = type[0].$rep;
|
|
2033
|
+
return value.every((v) => validateValueAgainstType(v, elementType));
|
|
2034
|
+
}
|
|
2035
|
+
return true;
|
|
2036
|
+
}
|
|
2037
|
+
if (isPlainObject(type)) {
|
|
2038
|
+
const orTypes = type.$or;
|
|
2039
|
+
if (Array.isArray(orTypes)) {
|
|
2040
|
+
return orTypes.some(
|
|
2041
|
+
(t) => validateValueAgainstType(value, t)
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
if ("$dict" in type) {
|
|
2045
|
+
const dictType = type.$dict;
|
|
2046
|
+
if (value instanceof Map) {
|
|
2047
|
+
for (const v of value.values()) {
|
|
2048
|
+
if (!validateValueAgainstType(v, dictType)) return false;
|
|
2049
|
+
}
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
if (!isPlainObject(value)) return false;
|
|
2053
|
+
return Object.values(value).every(
|
|
2054
|
+
(v) => validateValueAgainstType(v, dictType)
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
if (isPlainObject(value)) {
|
|
2058
|
+
return Object.entries(type).every(([key, keyType]) => {
|
|
2059
|
+
if (!(key in value)) return true;
|
|
2060
|
+
return validateValueAgainstType(
|
|
2061
|
+
value[key],
|
|
2062
|
+
keyType
|
|
2063
|
+
);
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
return true;
|
|
2068
|
+
}
|
|
1923
2069
|
export {
|
|
1924
2070
|
abi_exports as abi,
|
|
2071
|
+
buildGenVmPositionalArgs,
|
|
1925
2072
|
chains_exports as chains,
|
|
1926
2073
|
createAccount,
|
|
1927
2074
|
createClient,
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { I as BannedValidatorInfo,
|
|
2
|
+
export { I as BannedValidatorInfo, e as CalldataAddress, C as CalldataEncodable, j as ContractMethod, i as ContractMethodBase, g as ContractParamsArraySchemaElement, h as ContractParamsSchema, d as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a4 as DelegatorClaimOptions, a3 as DelegatorExitOptions, a2 as DelegatorJoinOptions, U as DelegatorJoinResult, K as EpochData, O as EpochInfo, G as GenLayerClient, f as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, L as LeaderReceipt, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a1 as SetIdentityOptions, a0 as SetOperatorOptions, y as SnapSource, J as StakeInfo, a5 as StakingActions, z as StakingContract, Q as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, _ as ValidatorClaimOptions, Y as ValidatorDepositOptions, Z as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, X as ValidatorJoinOptions, R as ValidatorJoinResult, $ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-CYszVbTS.cjs';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-B7B7UXdn.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { I as BannedValidatorInfo,
|
|
2
|
+
export { I as BannedValidatorInfo, e as CalldataAddress, C as CalldataEncodable, j as ContractMethod, i as ContractMethodBase, g as ContractParamsArraySchemaElement, h as ContractParamsSchema, d as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, a4 as DelegatorClaimOptions, a3 as DelegatorExitOptions, a2 as DelegatorJoinOptions, U as DelegatorJoinResult, K as EpochData, O as EpochInfo, G as GenLayerClient, f as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, L as LeaderReceipt, M as MethodDescription, N as Network, P as PendingDeposit, F as PendingWithdrawal, a1 as SetIdentityOptions, a0 as SetOperatorOptions, y as SnapSource, J as StakeInfo, a5 as StakingActions, z as StakingContract, Q as StakingTransactionResult, k as TransactionHash, x as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, w as TransactionType, _ as ValidatorClaimOptions, Y as ValidatorDepositOptions, Z as ValidatorExitOptions, B as ValidatorIdentity, E as ValidatorInfo, X as ValidatorJoinOptions, R as ValidatorJoinResult, $ as ValidatorPrimeOptions, A as ValidatorView, s as VoteType, W as WithdrawalCommit, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, u as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-CbVqYeWa.js';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-B7B7UXdn.js';
|