genlayer-js 0.9.4 → 0.10.0
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 +14 -0
- package/dist/{index-B_gpaVzJ.d.cts → index-BhRfI25e.d.cts} +5 -1
- package/dist/{index-to6d0Hzj.d.ts → index-dnt5ldCd.d.ts} +5 -1
- package/dist/index.cjs +86 -42
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +72 -28
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/contracts/actions.ts +90 -34
- package/src/types/clients.ts +6 -2
- package/tests/client.test.ts +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.10.0 (2025-05-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* adjust submitAppeal call to consensus smart contract ([#80](https://github.com/yeagerai/genlayer-js/issues/80)) ([9e4a88e](https://github.com/yeagerai/genlayer-js/commit/9e4a88ed9a094af067302f8c4aa170c7129bf53d))
|
|
9
|
+
|
|
10
|
+
## 0.9.5 (2025-05-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* update readContract with TransactionHashVariant ([#86](https://github.com/yeagerai/genlayer-js/issues/86)) ([7cbeb04](https://github.com/yeagerai/genlayer-js/commit/7cbeb040b55c4bc3acf173bdae51da51deef7a83))
|
|
16
|
+
|
|
3
17
|
## 0.9.4 (2025-05-20)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -323,12 +323,12 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
323
323
|
account?: Account;
|
|
324
324
|
address: Address;
|
|
325
325
|
functionName: string;
|
|
326
|
-
stateStatus?: TransactionStatus;
|
|
327
326
|
args?: CalldataEncodable[];
|
|
328
327
|
kwargs?: Map<string, CalldataEncodable> | {
|
|
329
328
|
[key: string]: CalldataEncodable;
|
|
330
329
|
};
|
|
331
330
|
rawReturn?: RawReturn;
|
|
331
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
332
332
|
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
333
333
|
writeContract: (args: {
|
|
334
334
|
account?: Account;
|
|
@@ -369,6 +369,10 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
369
369
|
initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
|
|
370
370
|
connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
|
|
371
371
|
metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
|
|
372
|
+
appealTransaction: (args: {
|
|
373
|
+
account?: Account;
|
|
374
|
+
txId: `0x${string}`;
|
|
375
|
+
}) => Promise<any>;
|
|
372
376
|
};
|
|
373
377
|
|
|
374
378
|
export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, TransactionResult as j, transactionsStatusNameToNumber as k, transactionResultNumberToName as l, TransactionResultNameToNumber as m, voteTypeNameToNumber as n, type TransactionType as o, TransactionHashVariant as p, type DecodedCallData as q, type GenLayerTransaction as r, type GenLayerRawTransaction as s, transactionsStatusNumberToName as t, voteTypeNumberToName as v };
|
|
@@ -323,12 +323,12 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
323
323
|
account?: Account;
|
|
324
324
|
address: Address;
|
|
325
325
|
functionName: string;
|
|
326
|
-
stateStatus?: TransactionStatus;
|
|
327
326
|
args?: CalldataEncodable[];
|
|
328
327
|
kwargs?: Map<string, CalldataEncodable> | {
|
|
329
328
|
[key: string]: CalldataEncodable;
|
|
330
329
|
};
|
|
331
330
|
rawReturn?: RawReturn;
|
|
331
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
332
332
|
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
333
333
|
writeContract: (args: {
|
|
334
334
|
account?: Account;
|
|
@@ -369,6 +369,10 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
369
369
|
initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
|
|
370
370
|
connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
|
|
371
371
|
metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
|
|
372
|
+
appealTransaction: (args: {
|
|
373
|
+
account?: Account;
|
|
374
|
+
txId: `0x${string}`;
|
|
375
|
+
}) => Promise<any>;
|
|
372
376
|
};
|
|
373
377
|
|
|
374
378
|
export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, TransactionResult as j, transactionsStatusNameToNumber as k, transactionResultNumberToName as l, TransactionResultNameToNumber as m, voteTypeNameToNumber as n, type TransactionType as o, TransactionHashVariant as p, type DecodedCallData as q, type GenLayerTransaction as r, type GenLayerRawTransaction as s, transactionsStatusNumberToName as t, voteTypeNumberToName as v };
|
package/dist/index.cjs
CHANGED
|
@@ -472,13 +472,19 @@ var contractActions = (client, publicClient) => {
|
|
|
472
472
|
} = args;
|
|
473
473
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
474
474
|
const serializedData = serialize(data);
|
|
475
|
-
|
|
475
|
+
const senderAccount = account || client.account;
|
|
476
|
+
const encodedData = _encodeAddTransactionData({
|
|
476
477
|
client,
|
|
477
|
-
|
|
478
|
+
senderAccount,
|
|
478
479
|
recipient: address,
|
|
479
480
|
data: serializedData,
|
|
480
|
-
|
|
481
|
-
|
|
481
|
+
consensusMaxRotations
|
|
482
|
+
});
|
|
483
|
+
return _sendTransaction({
|
|
484
|
+
client,
|
|
485
|
+
publicClient,
|
|
486
|
+
encodedData,
|
|
487
|
+
senderAccount,
|
|
482
488
|
value
|
|
483
489
|
});
|
|
484
490
|
},
|
|
@@ -497,55 +503,93 @@ var contractActions = (client, publicClient) => {
|
|
|
497
503
|
leaderOnly
|
|
498
504
|
];
|
|
499
505
|
const serializedData = serialize(data);
|
|
500
|
-
|
|
506
|
+
const senderAccount = account || client.account;
|
|
507
|
+
const encodedData = _encodeAddTransactionData({
|
|
501
508
|
client,
|
|
502
|
-
|
|
509
|
+
senderAccount,
|
|
503
510
|
recipient: _viem.zeroAddress,
|
|
504
511
|
data: serializedData,
|
|
505
|
-
senderAccount: account || client.account,
|
|
506
512
|
consensusMaxRotations
|
|
507
513
|
});
|
|
514
|
+
return _sendTransaction({
|
|
515
|
+
client,
|
|
516
|
+
publicClient,
|
|
517
|
+
encodedData,
|
|
518
|
+
senderAccount
|
|
519
|
+
});
|
|
520
|
+
},
|
|
521
|
+
appealTransaction: async (args) => {
|
|
522
|
+
const { account, txId } = args;
|
|
523
|
+
const senderAccount = account || client.account;
|
|
524
|
+
const encodedData = _encodeSubmitAppealData({ client, txId });
|
|
525
|
+
return _sendTransaction({
|
|
526
|
+
client,
|
|
527
|
+
publicClient,
|
|
528
|
+
encodedData,
|
|
529
|
+
senderAccount
|
|
530
|
+
});
|
|
508
531
|
}
|
|
509
532
|
};
|
|
510
533
|
};
|
|
511
|
-
var
|
|
512
|
-
|
|
513
|
-
publicClient,
|
|
514
|
-
recipient,
|
|
515
|
-
data,
|
|
516
|
-
senderAccount,
|
|
517
|
-
consensusMaxRotations,
|
|
518
|
-
value
|
|
519
|
-
}) => {
|
|
520
|
-
if (!senderAccount) {
|
|
534
|
+
var validateAccount = (Account3) => {
|
|
535
|
+
if (!Account3) {
|
|
521
536
|
throw new Error(
|
|
522
537
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
523
538
|
);
|
|
524
539
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
540
|
+
return Account3;
|
|
541
|
+
};
|
|
542
|
+
var _encodeAddTransactionData = ({
|
|
543
|
+
client,
|
|
544
|
+
senderAccount,
|
|
545
|
+
recipient,
|
|
546
|
+
data,
|
|
547
|
+
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
548
|
+
}) => {
|
|
549
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
550
|
+
return _viem.encodeFunctionData.call(void 0, {
|
|
551
|
+
abi: _optionalChain([client, 'access', _8 => _8.chain, 'access', _9 => _9.consensusMainContract, 'optionalAccess', _10 => _10.abi]),
|
|
530
552
|
functionName: "addTransaction",
|
|
531
553
|
args: [
|
|
532
|
-
|
|
554
|
+
validatedSenderAccount.address,
|
|
533
555
|
recipient,
|
|
534
556
|
client.chain.defaultNumberOfInitialValidators,
|
|
535
557
|
consensusMaxRotations,
|
|
536
558
|
data
|
|
537
559
|
]
|
|
538
560
|
});
|
|
539
|
-
|
|
561
|
+
};
|
|
562
|
+
var _encodeSubmitAppealData = ({
|
|
563
|
+
client,
|
|
564
|
+
txId
|
|
565
|
+
}) => {
|
|
566
|
+
return _viem.encodeFunctionData.call(void 0, {
|
|
567
|
+
abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.abi]),
|
|
568
|
+
functionName: "submitAppeal",
|
|
569
|
+
args: [txId]
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
var _sendTransaction = async ({
|
|
573
|
+
client,
|
|
574
|
+
publicClient,
|
|
575
|
+
encodedData,
|
|
576
|
+
senderAccount,
|
|
577
|
+
value = 0n
|
|
578
|
+
}) => {
|
|
579
|
+
if (!_optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.address])) {
|
|
580
|
+
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
581
|
+
}
|
|
582
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
583
|
+
const nonce = await client.getCurrentNonce({ address: validatedSenderAccount.address });
|
|
540
584
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
541
|
-
account:
|
|
542
|
-
to: _optionalChain([client, 'access',
|
|
585
|
+
account: validatedSenderAccount,
|
|
586
|
+
to: _optionalChain([client, 'access', _17 => _17.chain, 'access', _18 => _18.consensusMainContract, 'optionalAccess', _19 => _19.address]),
|
|
543
587
|
data: encodedData,
|
|
544
588
|
type: "legacy",
|
|
545
589
|
nonce: Number(nonce),
|
|
546
|
-
value
|
|
590
|
+
value
|
|
547
591
|
});
|
|
548
|
-
if (_optionalChain([
|
|
592
|
+
if (_optionalChain([validatedSenderAccount, 'optionalAccess', _20 => _20.type]) !== "local") {
|
|
549
593
|
const formattedRequest = {
|
|
550
594
|
from: transactionRequest.from,
|
|
551
595
|
to: transactionRequest.to,
|
|
@@ -557,17 +601,17 @@ var _sendTransaction = async ({
|
|
|
557
601
|
params: [formattedRequest]
|
|
558
602
|
});
|
|
559
603
|
}
|
|
560
|
-
if (!_optionalChain([
|
|
604
|
+
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _21 => _21.signTransaction])) {
|
|
561
605
|
throw new Error("Account does not support signTransaction");
|
|
562
606
|
}
|
|
563
|
-
const serializedTransaction = await
|
|
607
|
+
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
564
608
|
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
565
609
|
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
566
610
|
if (receipt.status === "reverted") {
|
|
567
611
|
throw new Error("Transaction reverted");
|
|
568
612
|
}
|
|
569
613
|
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
570
|
-
abi: _optionalChain([client, 'access',
|
|
614
|
+
abi: _optionalChain([client, 'access', _22 => _22.chain, 'access', _23 => _23.consensusMainContract, 'optionalAccess', _24 => _24.abi]),
|
|
571
615
|
eventName: "NewTransaction",
|
|
572
616
|
logs: receipt.logs
|
|
573
617
|
});
|
|
@@ -683,8 +727,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
683
727
|
return _decodeLocalnetTransaction(transaction2);
|
|
684
728
|
}
|
|
685
729
|
const transaction = await publicClient.readContract({
|
|
686
|
-
address: _optionalChain([client, 'access',
|
|
687
|
-
abi: _optionalChain([client, 'access',
|
|
730
|
+
address: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusDataContract, 'optionalAccess', _27 => _27.address]),
|
|
731
|
+
abi: _optionalChain([client, 'access', _28 => _28.chain, 'access', _29 => _29.consensusDataContract, 'optionalAccess', _30 => _30.abi]),
|
|
688
732
|
functionName: "getTransactionData",
|
|
689
733
|
args: [
|
|
690
734
|
hash,
|
|
@@ -772,7 +816,7 @@ var _decodeTransaction = (tx) => {
|
|
|
772
816
|
var _decodeLocalnetTransaction = (tx) => {
|
|
773
817
|
if (!tx.data) return tx;
|
|
774
818
|
try {
|
|
775
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
819
|
+
const leaderReceipt = _optionalChain([tx, 'access', _31 => _31.consensus_data, 'optionalAccess', _32 => _32.leader_receipt]);
|
|
776
820
|
if (leaderReceipt) {
|
|
777
821
|
if (leaderReceipt.result && typeof leaderReceipt.result === "string") {
|
|
778
822
|
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
@@ -792,7 +836,7 @@ var _decodeLocalnetTransaction = (tx) => {
|
|
|
792
836
|
);
|
|
793
837
|
}
|
|
794
838
|
}
|
|
795
|
-
if (_optionalChain([tx, 'access',
|
|
839
|
+
if (_optionalChain([tx, 'access', _33 => _33.data, 'optionalAccess', _34 => _34.calldata]) && typeof tx.data.calldata === "string") {
|
|
796
840
|
tx.data.calldata = {
|
|
797
841
|
base64: tx.data.calldata,
|
|
798
842
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -4845,7 +4889,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
4845
4889
|
chainName: selectedNetwork.name,
|
|
4846
4890
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
4847
4891
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
4848
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
4892
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _35 => _35.blockExplorers, 'optionalAccess', _36 => _36.default, 'access', _37 => _37.url])]
|
|
4849
4893
|
};
|
|
4850
4894
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
4851
4895
|
if (currentChainId !== chainIdHex) {
|
|
@@ -4879,10 +4923,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
4879
4923
|
}
|
|
4880
4924
|
const isFlask = async () => {
|
|
4881
4925
|
try {
|
|
4882
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
4926
|
+
const clientVersion = await _optionalChain([window, 'access', _38 => _38.ethereum, 'optionalAccess', _39 => _39.request, 'call', _40 => _40({
|
|
4883
4927
|
method: "web3_clientVersion"
|
|
4884
4928
|
})]);
|
|
4885
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
4929
|
+
return _optionalChain([clientVersion, 'optionalAccess', _41 => _41.includes, 'call', _42 => _42("flask")]);
|
|
4886
4930
|
} catch (error) {
|
|
4887
4931
|
console.error("Error detecting Flask:", error);
|
|
4888
4932
|
return false;
|
|
@@ -4890,7 +4934,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
4890
4934
|
};
|
|
4891
4935
|
const installedSnaps = async () => {
|
|
4892
4936
|
try {
|
|
4893
|
-
return await _optionalChain([window, 'access',
|
|
4937
|
+
return await _optionalChain([window, 'access', _43 => _43.ethereum, 'optionalAccess', _44 => _44.request, 'call', _45 => _45({
|
|
4894
4938
|
method: "wallet_getSnaps"
|
|
4895
4939
|
})]);
|
|
4896
4940
|
} catch (error) {
|
|
@@ -4925,10 +4969,10 @@ function walletActions(client) {
|
|
|
4925
4969
|
function chainActions(client) {
|
|
4926
4970
|
return {
|
|
4927
4971
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
4928
|
-
if (_optionalChain([client, 'access',
|
|
4972
|
+
if (_optionalChain([client, 'access', _46 => _46.chain, 'optionalAccess', _47 => _47.id]) === _chunkSMCXL465cjs.testnetAsimov.id) {
|
|
4929
4973
|
return;
|
|
4930
4974
|
}
|
|
4931
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
4975
|
+
if (!forceReset && _optionalChain([client, 'access', _48 => _48.chain, 'access', _49 => _49.consensusMainContract, 'optionalAccess', _50 => _50.address]) && _optionalChain([client, 'access', _51 => _51.chain, 'access', _52 => _52.consensusMainContract, 'optionalAccess', _53 => _53.abi])) {
|
|
4932
4976
|
return;
|
|
4933
4977
|
}
|
|
4934
4978
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -4959,7 +5003,7 @@ var getCustomTransportConfig = (config) => {
|
|
|
4959
5003
|
async request({ method, params = [] }) {
|
|
4960
5004
|
if (method.startsWith("eth_") && isAddress) {
|
|
4961
5005
|
try {
|
|
4962
|
-
return await _optionalChain([window, 'access',
|
|
5006
|
+
return await _optionalChain([window, 'access', _54 => _54.ethereum, 'optionalAccess', _55 => _55.request, 'call', _56 => _56({ method, params })]);
|
|
4963
5007
|
} catch (err) {
|
|
4964
5008
|
console.warn(`Error using window.ethereum for method ${method}:`, err);
|
|
4965
5009
|
throw err;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-BhRfI25e.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 } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-BYSCF33g.js';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-dnt5ldCd.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';
|
package/dist/index.js
CHANGED
|
@@ -472,13 +472,19 @@ var contractActions = (client, publicClient) => {
|
|
|
472
472
|
} = args;
|
|
473
473
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
474
474
|
const serializedData = serialize(data);
|
|
475
|
-
|
|
475
|
+
const senderAccount = account || client.account;
|
|
476
|
+
const encodedData = _encodeAddTransactionData({
|
|
476
477
|
client,
|
|
477
|
-
|
|
478
|
+
senderAccount,
|
|
478
479
|
recipient: address,
|
|
479
480
|
data: serializedData,
|
|
480
|
-
|
|
481
|
-
|
|
481
|
+
consensusMaxRotations
|
|
482
|
+
});
|
|
483
|
+
return _sendTransaction({
|
|
484
|
+
client,
|
|
485
|
+
publicClient,
|
|
486
|
+
encodedData,
|
|
487
|
+
senderAccount,
|
|
482
488
|
value
|
|
483
489
|
});
|
|
484
490
|
},
|
|
@@ -497,55 +503,93 @@ var contractActions = (client, publicClient) => {
|
|
|
497
503
|
leaderOnly
|
|
498
504
|
];
|
|
499
505
|
const serializedData = serialize(data);
|
|
500
|
-
|
|
506
|
+
const senderAccount = account || client.account;
|
|
507
|
+
const encodedData = _encodeAddTransactionData({
|
|
501
508
|
client,
|
|
502
|
-
|
|
509
|
+
senderAccount,
|
|
503
510
|
recipient: zeroAddress,
|
|
504
511
|
data: serializedData,
|
|
505
|
-
senderAccount: account || client.account,
|
|
506
512
|
consensusMaxRotations
|
|
507
513
|
});
|
|
514
|
+
return _sendTransaction({
|
|
515
|
+
client,
|
|
516
|
+
publicClient,
|
|
517
|
+
encodedData,
|
|
518
|
+
senderAccount
|
|
519
|
+
});
|
|
520
|
+
},
|
|
521
|
+
appealTransaction: async (args) => {
|
|
522
|
+
const { account, txId } = args;
|
|
523
|
+
const senderAccount = account || client.account;
|
|
524
|
+
const encodedData = _encodeSubmitAppealData({ client, txId });
|
|
525
|
+
return _sendTransaction({
|
|
526
|
+
client,
|
|
527
|
+
publicClient,
|
|
528
|
+
encodedData,
|
|
529
|
+
senderAccount
|
|
530
|
+
});
|
|
508
531
|
}
|
|
509
532
|
};
|
|
510
533
|
};
|
|
511
|
-
var
|
|
512
|
-
|
|
513
|
-
publicClient,
|
|
514
|
-
recipient,
|
|
515
|
-
data,
|
|
516
|
-
senderAccount,
|
|
517
|
-
consensusMaxRotations,
|
|
518
|
-
value
|
|
519
|
-
}) => {
|
|
520
|
-
if (!senderAccount) {
|
|
534
|
+
var validateAccount = (Account3) => {
|
|
535
|
+
if (!Account3) {
|
|
521
536
|
throw new Error(
|
|
522
537
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
523
538
|
);
|
|
524
539
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
540
|
+
return Account3;
|
|
541
|
+
};
|
|
542
|
+
var _encodeAddTransactionData = ({
|
|
543
|
+
client,
|
|
544
|
+
senderAccount,
|
|
545
|
+
recipient,
|
|
546
|
+
data,
|
|
547
|
+
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
548
|
+
}) => {
|
|
549
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
550
|
+
return encodeFunctionData({
|
|
529
551
|
abi: client.chain.consensusMainContract?.abi,
|
|
530
552
|
functionName: "addTransaction",
|
|
531
553
|
args: [
|
|
532
|
-
|
|
554
|
+
validatedSenderAccount.address,
|
|
533
555
|
recipient,
|
|
534
556
|
client.chain.defaultNumberOfInitialValidators,
|
|
535
557
|
consensusMaxRotations,
|
|
536
558
|
data
|
|
537
559
|
]
|
|
538
560
|
});
|
|
539
|
-
|
|
561
|
+
};
|
|
562
|
+
var _encodeSubmitAppealData = ({
|
|
563
|
+
client,
|
|
564
|
+
txId
|
|
565
|
+
}) => {
|
|
566
|
+
return encodeFunctionData({
|
|
567
|
+
abi: client.chain.consensusMainContract?.abi,
|
|
568
|
+
functionName: "submitAppeal",
|
|
569
|
+
args: [txId]
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
var _sendTransaction = async ({
|
|
573
|
+
client,
|
|
574
|
+
publicClient,
|
|
575
|
+
encodedData,
|
|
576
|
+
senderAccount,
|
|
577
|
+
value = 0n
|
|
578
|
+
}) => {
|
|
579
|
+
if (!client.chain.consensusMainContract?.address) {
|
|
580
|
+
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
581
|
+
}
|
|
582
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
583
|
+
const nonce = await client.getCurrentNonce({ address: validatedSenderAccount.address });
|
|
540
584
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
541
|
-
account:
|
|
585
|
+
account: validatedSenderAccount,
|
|
542
586
|
to: client.chain.consensusMainContract?.address,
|
|
543
587
|
data: encodedData,
|
|
544
588
|
type: "legacy",
|
|
545
589
|
nonce: Number(nonce),
|
|
546
|
-
value
|
|
590
|
+
value
|
|
547
591
|
});
|
|
548
|
-
if (
|
|
592
|
+
if (validatedSenderAccount?.type !== "local") {
|
|
549
593
|
const formattedRequest = {
|
|
550
594
|
from: transactionRequest.from,
|
|
551
595
|
to: transactionRequest.to,
|
|
@@ -557,10 +601,10 @@ var _sendTransaction = async ({
|
|
|
557
601
|
params: [formattedRequest]
|
|
558
602
|
});
|
|
559
603
|
}
|
|
560
|
-
if (!
|
|
604
|
+
if (!validatedSenderAccount?.signTransaction) {
|
|
561
605
|
throw new Error("Account does not support signTransaction");
|
|
562
606
|
}
|
|
563
|
-
const serializedTransaction = await
|
|
607
|
+
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
564
608
|
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
565
609
|
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
566
610
|
if (receipt.status === "reverted") {
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, q as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, b as GenLayerMethod, s as GenLayerRawTransaction, r as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, h as TransactionHash, p as TransactionHashVariant, j as TransactionResult, m as TransactionResultNameToNumber, i as TransactionStatus, o as TransactionType, V as VoteType, l as transactionResultNumberToName, k as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, n as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, q as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, b as GenLayerMethod, s as GenLayerRawTransaction, r as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, h as TransactionHash, p as TransactionHashVariant, j as TransactionResult, m as TransactionResultNameToNumber, i as TransactionStatus, o as TransactionType, V as VoteType, l as transactionResultNumberToName, k as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, n as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-BhRfI25e.cjs';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, q as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, b as GenLayerMethod, s as GenLayerRawTransaction, r as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, h as TransactionHash, p as TransactionHashVariant, j as TransactionResult, m as TransactionResultNameToNumber, i as TransactionStatus, o as TransactionType, V as VoteType, l as transactionResultNumberToName, k as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, n as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, q as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, b as GenLayerMethod, s as GenLayerRawTransaction, r as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, h as TransactionHash, p as TransactionHashVariant, j as TransactionResult, m as TransactionResultNameToNumber, i as TransactionStatus, o as TransactionType, V as VoteType, l as transactionResultNumberToName, k as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, n as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-dnt5ldCd.js';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.js';
|
package/package.json
CHANGED
package/src/contracts/actions.ts
CHANGED
|
@@ -137,13 +137,19 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
137
137
|
} = args;
|
|
138
138
|
const data = [calldata.encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
139
139
|
const serializedData = serialize(data);
|
|
140
|
-
|
|
140
|
+
const senderAccount = account || client.account;
|
|
141
|
+
const encodedData = _encodeAddTransactionData({
|
|
141
142
|
client,
|
|
142
|
-
|
|
143
|
+
senderAccount,
|
|
143
144
|
recipient: address,
|
|
144
145
|
data: serializedData,
|
|
145
|
-
senderAccount: account || client.account,
|
|
146
146
|
consensusMaxRotations,
|
|
147
|
+
});
|
|
148
|
+
return _sendTransaction({
|
|
149
|
+
client,
|
|
150
|
+
publicClient,
|
|
151
|
+
encodedData,
|
|
152
|
+
senderAccount,
|
|
147
153
|
value,
|
|
148
154
|
});
|
|
149
155
|
},
|
|
@@ -169,68 +175,118 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
169
175
|
leaderOnly,
|
|
170
176
|
];
|
|
171
177
|
const serializedData = serialize(data);
|
|
172
|
-
|
|
178
|
+
const senderAccount = account || client.account;
|
|
179
|
+
const encodedData = _encodeAddTransactionData({
|
|
173
180
|
client,
|
|
174
|
-
|
|
181
|
+
senderAccount,
|
|
175
182
|
recipient: zeroAddress,
|
|
176
183
|
data: serializedData,
|
|
177
|
-
senderAccount: account || client.account,
|
|
178
184
|
consensusMaxRotations,
|
|
179
185
|
});
|
|
186
|
+
return _sendTransaction({
|
|
187
|
+
client,
|
|
188
|
+
publicClient,
|
|
189
|
+
encodedData,
|
|
190
|
+
senderAccount,
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
appealTransaction: async (args: {
|
|
194
|
+
account?: Account;
|
|
195
|
+
txId: `0x${string}`;
|
|
196
|
+
}) => {
|
|
197
|
+
const {account, txId} = args;
|
|
198
|
+
const senderAccount = account || client.account;
|
|
199
|
+
const encodedData = _encodeSubmitAppealData({client, txId});
|
|
200
|
+
return _sendTransaction({
|
|
201
|
+
client,
|
|
202
|
+
publicClient,
|
|
203
|
+
encodedData,
|
|
204
|
+
senderAccount,
|
|
205
|
+
});
|
|
180
206
|
},
|
|
181
207
|
};
|
|
182
208
|
};
|
|
183
209
|
|
|
184
|
-
const
|
|
210
|
+
const validateAccount = (Account?: Account): Account => {
|
|
211
|
+
if (!Account) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"No account set. Configure the client with an account or pass an account to this function.",
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return Account;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const _encodeAddTransactionData = ({
|
|
185
220
|
client,
|
|
186
|
-
|
|
221
|
+
senderAccount,
|
|
187
222
|
recipient,
|
|
188
223
|
data,
|
|
189
|
-
|
|
190
|
-
consensusMaxRotations,
|
|
191
|
-
value,
|
|
224
|
+
consensusMaxRotations = client.chain.defaultConsensusMaxRotations,
|
|
192
225
|
}: {
|
|
193
226
|
client: GenLayerClient<GenLayerChain>;
|
|
194
|
-
publicClient: PublicClient;
|
|
195
|
-
recipient: `0x${string}`;
|
|
196
|
-
data: `0x${string}`;
|
|
197
227
|
senderAccount?: Account;
|
|
228
|
+
recipient?: `0x${string}`;
|
|
229
|
+
data?: `0x${string}`;
|
|
198
230
|
consensusMaxRotations?: number;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
throw new Error(
|
|
203
|
-
"No account set. Configure the client with an account or pass an account to this function.",
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (!client.chain.consensusMainContract?.address) {
|
|
208
|
-
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const encodedData = encodeFunctionData({
|
|
231
|
+
}): `0x${string}` => {
|
|
232
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
233
|
+
return encodeFunctionData({
|
|
212
234
|
abi: client.chain.consensusMainContract?.abi as any,
|
|
213
235
|
functionName: "addTransaction",
|
|
214
236
|
args: [
|
|
215
|
-
|
|
237
|
+
validatedSenderAccount.address,
|
|
216
238
|
recipient,
|
|
217
239
|
client.chain.defaultNumberOfInitialValidators,
|
|
218
240
|
consensusMaxRotations,
|
|
219
241
|
data,
|
|
220
242
|
],
|
|
221
243
|
});
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const _encodeSubmitAppealData = ({
|
|
247
|
+
client,
|
|
248
|
+
txId,
|
|
249
|
+
}: {
|
|
250
|
+
client: GenLayerClient<GenLayerChain>;
|
|
251
|
+
txId: `0x${string}`;
|
|
252
|
+
}): `0x${string}` => {
|
|
253
|
+
return encodeFunctionData({
|
|
254
|
+
abi: client.chain.consensusMainContract?.abi as any,
|
|
255
|
+
functionName: "submitAppeal",
|
|
256
|
+
args: [txId],
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const _sendTransaction = async ({
|
|
261
|
+
client,
|
|
262
|
+
publicClient,
|
|
263
|
+
encodedData,
|
|
264
|
+
senderAccount,
|
|
265
|
+
value = 0n,
|
|
266
|
+
}: {
|
|
267
|
+
client: GenLayerClient<GenLayerChain>;
|
|
268
|
+
publicClient: PublicClient;
|
|
269
|
+
encodedData: `0x${string}`;
|
|
270
|
+
senderAccount?: Account;
|
|
271
|
+
value?: bigint;
|
|
272
|
+
}) => {
|
|
273
|
+
if (!client.chain.consensusMainContract?.address) {
|
|
274
|
+
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const validatedSenderAccount = validateAccount(senderAccount);
|
|
222
278
|
|
|
223
|
-
const nonce = await client.getCurrentNonce({address:
|
|
279
|
+
const nonce = await client.getCurrentNonce({address: validatedSenderAccount.address});
|
|
224
280
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
225
|
-
account:
|
|
281
|
+
account: validatedSenderAccount,
|
|
226
282
|
to: client.chain.consensusMainContract?.address as Address,
|
|
227
283
|
data: encodedData,
|
|
228
284
|
type: "legacy",
|
|
229
285
|
nonce: Number(nonce),
|
|
230
|
-
value: value
|
|
286
|
+
value: value,
|
|
231
287
|
});
|
|
232
288
|
|
|
233
|
-
if (
|
|
289
|
+
if (validatedSenderAccount?.type !== "local") {
|
|
234
290
|
const formattedRequest = {
|
|
235
291
|
from: transactionRequest.from,
|
|
236
292
|
to: transactionRequest.to,
|
|
@@ -244,11 +300,11 @@ const _sendTransaction = async ({
|
|
|
244
300
|
});
|
|
245
301
|
}
|
|
246
302
|
|
|
247
|
-
if (!
|
|
303
|
+
if (!validatedSenderAccount?.signTransaction) {
|
|
248
304
|
throw new Error("Account does not support signTransaction");
|
|
249
305
|
}
|
|
250
306
|
|
|
251
|
-
const serializedTransaction = await
|
|
307
|
+
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
252
308
|
|
|
253
309
|
const txHash = await client.sendRawTransaction({serializedTransaction: serializedTransaction});
|
|
254
310
|
|
package/src/types/clients.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Transport, Client, PublicActions, WalletActions} from "viem";
|
|
2
|
-
import {GenLayerTransaction, TransactionHash, TransactionStatus} from "./transactions";
|
|
2
|
+
import {GenLayerTransaction, TransactionHash, TransactionStatus, TransactionHashVariant} from "./transactions";
|
|
3
3
|
import {GenLayerChain} from "./chains";
|
|
4
4
|
import {Address, Account} from "./accounts";
|
|
5
5
|
import {CalldataEncodable} from "./calldata";
|
|
@@ -43,10 +43,10 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
|
|
|
43
43
|
account?: Account;
|
|
44
44
|
address: Address;
|
|
45
45
|
functionName: string;
|
|
46
|
-
stateStatus?: TransactionStatus;
|
|
47
46
|
args?: CalldataEncodable[];
|
|
48
47
|
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
49
48
|
rawReturn?: RawReturn;
|
|
49
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
50
50
|
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
51
51
|
writeContract: (args: {
|
|
52
52
|
account?: Account;
|
|
@@ -79,4 +79,8 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
|
|
|
79
79
|
initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
|
|
80
80
|
connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
|
|
81
81
|
metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
|
|
82
|
+
appealTransaction: (args: {
|
|
83
|
+
account?: Account;
|
|
84
|
+
txId: `0x${string}`;
|
|
85
|
+
}) => Promise<any>;
|
|
82
86
|
};
|
package/tests/client.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {localnet} from "@/chains/localnet";
|
|
|
4
4
|
import {Address} from "../src/types/accounts";
|
|
5
5
|
import {createAccount, generatePrivateKey} from "../src/accounts/account";
|
|
6
6
|
import {vi} from "vitest";
|
|
7
|
-
import {
|
|
7
|
+
import {TransactionHashVariant} from "../src/types/transactions";
|
|
8
8
|
|
|
9
9
|
// Setup fetch mock
|
|
10
10
|
const mockFetch = vi.fn();
|
|
@@ -95,7 +95,7 @@ describe("Client Overrides", () => {
|
|
|
95
95
|
address: contractAddress as Address,
|
|
96
96
|
functionName: "testFunction",
|
|
97
97
|
args: ["arg1", "arg2"],
|
|
98
|
-
|
|
98
|
+
transactionHashVariant: TransactionHashVariant.LATEST_NONFINAL,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
expect(lastGenCallParams).toEqual([
|
|
@@ -104,7 +104,7 @@ describe("Client Overrides", () => {
|
|
|
104
104
|
to: contractAddress,
|
|
105
105
|
from: account.address,
|
|
106
106
|
data: expect.any(String), // The data is complex, checking type is often sufficient
|
|
107
|
-
transaction_hash_variant:
|
|
107
|
+
transaction_hash_variant: TransactionHashVariant.LATEST_NONFINAL,
|
|
108
108
|
},
|
|
109
109
|
]);
|
|
110
110
|
});
|
|
@@ -126,7 +126,7 @@ describe("Client Overrides", () => {
|
|
|
126
126
|
address: contractAddress as Address,
|
|
127
127
|
functionName: "testFunction",
|
|
128
128
|
args: ["arg1", "arg2"],
|
|
129
|
-
|
|
129
|
+
transactionHashVariant: TransactionHashVariant.LATEST_FINAL,
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
expect(lastGenCallParams).toEqual([
|
|
@@ -135,7 +135,7 @@ describe("Client Overrides", () => {
|
|
|
135
135
|
to: contractAddress,
|
|
136
136
|
from: overrideAccount.address,
|
|
137
137
|
data: expect.any(String),
|
|
138
|
-
transaction_hash_variant:
|
|
138
|
+
transaction_hash_variant: TransactionHashVariant.LATEST_FINAL,
|
|
139
139
|
},
|
|
140
140
|
]);
|
|
141
141
|
});
|
|
@@ -164,7 +164,7 @@ describe("Client Overrides", () => {
|
|
|
164
164
|
to: contractAddress,
|
|
165
165
|
from: accountAddressString, // Expecting the address string directly
|
|
166
166
|
data: expect.any(String),
|
|
167
|
-
transaction_hash_variant:
|
|
167
|
+
transaction_hash_variant: TransactionHashVariant.LATEST_FINAL,
|
|
168
168
|
},
|
|
169
169
|
]);
|
|
170
170
|
});
|