genlayer-js 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.cjs +61 -17
- package/dist/index.js +44 -0
- package/package.json +1 -1
- package/src/contracts/actions.ts +67 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -438,6 +438,20 @@ var contractActions = (client, publicClient) => {
|
|
|
438
438
|
leaderOnly = false,
|
|
439
439
|
transactionHashVariant = "latest-final" /* LATEST_FINAL */
|
|
440
440
|
} = args;
|
|
441
|
+
if (client.chain.id === _chunkSMCXL465cjs.localnet.id) {
|
|
442
|
+
return _localnetReadContract({
|
|
443
|
+
client,
|
|
444
|
+
args: {
|
|
445
|
+
account,
|
|
446
|
+
address,
|
|
447
|
+
functionName,
|
|
448
|
+
args: callArgs,
|
|
449
|
+
kwargs,
|
|
450
|
+
stateStatus: transactionHashVariant === "latest-final" /* LATEST_FINAL */ ? "FINALIZED" /* FINALIZED */ : "ACCEPTED" /* ACCEPTED */,
|
|
451
|
+
rawReturn: _nullishCoalesce(args.rawReturn, () => ( false))
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
441
455
|
const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
442
456
|
const serializedData = serialize(encodedData);
|
|
443
457
|
const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address])));
|
|
@@ -508,6 +522,36 @@ var contractActions = (client, publicClient) => {
|
|
|
508
522
|
}
|
|
509
523
|
};
|
|
510
524
|
};
|
|
525
|
+
var _localnetReadContract = async ({
|
|
526
|
+
client,
|
|
527
|
+
args
|
|
528
|
+
}) => {
|
|
529
|
+
const {
|
|
530
|
+
account,
|
|
531
|
+
address,
|
|
532
|
+
functionName,
|
|
533
|
+
args: callArgs,
|
|
534
|
+
kwargs,
|
|
535
|
+
stateStatus = "ACCEPTED" /* ACCEPTED */
|
|
536
|
+
} = args;
|
|
537
|
+
const encodedData = encode(makeCalldataObject(functionName, callArgs, kwargs));
|
|
538
|
+
const serializedData = serializeOne(encodedData);
|
|
539
|
+
const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _8 => _8.address]), () => ( _optionalChain([client, 'access', _9 => _9.account, 'optionalAccess', _10 => _10.address])));
|
|
540
|
+
const requestParams = {
|
|
541
|
+
to: address,
|
|
542
|
+
from: senderAddress,
|
|
543
|
+
data: serializedData
|
|
544
|
+
};
|
|
545
|
+
const result = await client.request({
|
|
546
|
+
method: "eth_call",
|
|
547
|
+
params: [requestParams, stateStatus == "FINALIZED" /* FINALIZED */ ? "finalized" : "latest"]
|
|
548
|
+
});
|
|
549
|
+
if (args.rawReturn) {
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
const resultBinary = _viem.fromHex.call(void 0, result, "bytes");
|
|
553
|
+
return decode(resultBinary);
|
|
554
|
+
};
|
|
511
555
|
var _sendTransaction = async ({
|
|
512
556
|
client,
|
|
513
557
|
publicClient,
|
|
@@ -522,11 +566,11 @@ var _sendTransaction = async ({
|
|
|
522
566
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
523
567
|
);
|
|
524
568
|
}
|
|
525
|
-
if (!_optionalChain([client, 'access',
|
|
569
|
+
if (!_optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.address])) {
|
|
526
570
|
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
527
571
|
}
|
|
528
572
|
const encodedData = _viem.encodeFunctionData.call(void 0, {
|
|
529
|
-
abi: _optionalChain([client, 'access',
|
|
573
|
+
abi: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.abi]),
|
|
530
574
|
functionName: "addTransaction",
|
|
531
575
|
args: [
|
|
532
576
|
senderAccount.address,
|
|
@@ -539,13 +583,13 @@ var _sendTransaction = async ({
|
|
|
539
583
|
const nonce = await client.getCurrentNonce({ address: senderAccount.address });
|
|
540
584
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
541
585
|
account: senderAccount,
|
|
542
|
-
to: _optionalChain([client, 'access',
|
|
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
590
|
value: _nullishCoalesce(value, () => ( 0n))
|
|
547
591
|
});
|
|
548
|
-
if (_optionalChain([senderAccount, 'optionalAccess',
|
|
592
|
+
if (_optionalChain([senderAccount, 'optionalAccess', _20 => _20.type]) !== "local") {
|
|
549
593
|
const formattedRequest = {
|
|
550
594
|
from: transactionRequest.from,
|
|
551
595
|
to: transactionRequest.to,
|
|
@@ -557,7 +601,7 @@ var _sendTransaction = async ({
|
|
|
557
601
|
params: [formattedRequest]
|
|
558
602
|
});
|
|
559
603
|
}
|
|
560
|
-
if (!_optionalChain([senderAccount, 'optionalAccess',
|
|
604
|
+
if (!_optionalChain([senderAccount, 'optionalAccess', _21 => _21.signTransaction])) {
|
|
561
605
|
throw new Error("Account does not support signTransaction");
|
|
562
606
|
}
|
|
563
607
|
const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
|
|
@@ -570,7 +614,7 @@ var _sendTransaction = async ({
|
|
|
570
614
|
throw new Error("Transaction reverted");
|
|
571
615
|
}
|
|
572
616
|
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
573
|
-
abi: _optionalChain([client, 'access',
|
|
617
|
+
abi: _optionalChain([client, 'access', _22 => _22.chain, 'access', _23 => _23.consensusMainContract, 'optionalAccess', _24 => _24.abi]),
|
|
574
618
|
eventName: "NewTransaction",
|
|
575
619
|
logs: receipt.logs
|
|
576
620
|
});
|
|
@@ -686,8 +730,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
686
730
|
return _decodeLocalnetTransaction(transaction2);
|
|
687
731
|
}
|
|
688
732
|
const transaction = await publicClient.readContract({
|
|
689
|
-
address: _optionalChain([client, 'access',
|
|
690
|
-
abi: _optionalChain([client, 'access',
|
|
733
|
+
address: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusDataContract, 'optionalAccess', _27 => _27.address]),
|
|
734
|
+
abi: _optionalChain([client, 'access', _28 => _28.chain, 'access', _29 => _29.consensusDataContract, 'optionalAccess', _30 => _30.abi]),
|
|
691
735
|
functionName: "getTransactionData",
|
|
692
736
|
args: [
|
|
693
737
|
hash,
|
|
@@ -775,7 +819,7 @@ var _decodeTransaction = (tx) => {
|
|
|
775
819
|
var _decodeLocalnetTransaction = (tx) => {
|
|
776
820
|
if (!tx.data) return tx;
|
|
777
821
|
try {
|
|
778
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
822
|
+
const leaderReceipt = _optionalChain([tx, 'access', _31 => _31.consensus_data, 'optionalAccess', _32 => _32.leader_receipt]);
|
|
779
823
|
if (leaderReceipt) {
|
|
780
824
|
if (leaderReceipt.result && typeof leaderReceipt.result === "string") {
|
|
781
825
|
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
@@ -795,7 +839,7 @@ var _decodeLocalnetTransaction = (tx) => {
|
|
|
795
839
|
);
|
|
796
840
|
}
|
|
797
841
|
}
|
|
798
|
-
if (_optionalChain([tx, 'access',
|
|
842
|
+
if (_optionalChain([tx, 'access', _33 => _33.data, 'optionalAccess', _34 => _34.calldata]) && typeof tx.data.calldata === "string") {
|
|
799
843
|
tx.data.calldata = {
|
|
800
844
|
base64: tx.data.calldata,
|
|
801
845
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -4848,7 +4892,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
4848
4892
|
chainName: selectedNetwork.name,
|
|
4849
4893
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
4850
4894
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
4851
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
4895
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _35 => _35.blockExplorers, 'optionalAccess', _36 => _36.default, 'access', _37 => _37.url])]
|
|
4852
4896
|
};
|
|
4853
4897
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
4854
4898
|
if (currentChainId !== chainIdHex) {
|
|
@@ -4882,10 +4926,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
4882
4926
|
}
|
|
4883
4927
|
const isFlask = async () => {
|
|
4884
4928
|
try {
|
|
4885
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
4929
|
+
const clientVersion = await _optionalChain([window, 'access', _38 => _38.ethereum, 'optionalAccess', _39 => _39.request, 'call', _40 => _40({
|
|
4886
4930
|
method: "web3_clientVersion"
|
|
4887
4931
|
})]);
|
|
4888
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
4932
|
+
return _optionalChain([clientVersion, 'optionalAccess', _41 => _41.includes, 'call', _42 => _42("flask")]);
|
|
4889
4933
|
} catch (error) {
|
|
4890
4934
|
console.error("Error detecting Flask:", error);
|
|
4891
4935
|
return false;
|
|
@@ -4893,7 +4937,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
4893
4937
|
};
|
|
4894
4938
|
const installedSnaps = async () => {
|
|
4895
4939
|
try {
|
|
4896
|
-
return await _optionalChain([window, 'access',
|
|
4940
|
+
return await _optionalChain([window, 'access', _43 => _43.ethereum, 'optionalAccess', _44 => _44.request, 'call', _45 => _45({
|
|
4897
4941
|
method: "wallet_getSnaps"
|
|
4898
4942
|
})]);
|
|
4899
4943
|
} catch (error) {
|
|
@@ -4928,10 +4972,10 @@ function walletActions(client) {
|
|
|
4928
4972
|
function chainActions(client) {
|
|
4929
4973
|
return {
|
|
4930
4974
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
4931
|
-
if (_optionalChain([client, 'access',
|
|
4975
|
+
if (_optionalChain([client, 'access', _46 => _46.chain, 'optionalAccess', _47 => _47.id]) === _chunkSMCXL465cjs.testnetAsimov.id) {
|
|
4932
4976
|
return;
|
|
4933
4977
|
}
|
|
4934
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
4978
|
+
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])) {
|
|
4935
4979
|
return;
|
|
4936
4980
|
}
|
|
4937
4981
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -4962,7 +5006,7 @@ var getCustomTransportConfig = (config) => {
|
|
|
4962
5006
|
async request({ method, params = [] }) {
|
|
4963
5007
|
if (method.startsWith("eth_") && isAddress) {
|
|
4964
5008
|
try {
|
|
4965
|
-
return await _optionalChain([window, 'access',
|
|
5009
|
+
return await _optionalChain([window, 'access', _54 => _54.ethereum, 'optionalAccess', _55 => _55.request, 'call', _56 => _56({ method, params })]);
|
|
4966
5010
|
} catch (err) {
|
|
4967
5011
|
console.warn(`Error using window.ethereum for method ${method}:`, err);
|
|
4968
5012
|
throw err;
|
package/dist/index.js
CHANGED
|
@@ -438,6 +438,20 @@ var contractActions = (client, publicClient) => {
|
|
|
438
438
|
leaderOnly = false,
|
|
439
439
|
transactionHashVariant = "latest-final" /* LATEST_FINAL */
|
|
440
440
|
} = args;
|
|
441
|
+
if (client.chain.id === localnet.id) {
|
|
442
|
+
return _localnetReadContract({
|
|
443
|
+
client,
|
|
444
|
+
args: {
|
|
445
|
+
account,
|
|
446
|
+
address,
|
|
447
|
+
functionName,
|
|
448
|
+
args: callArgs,
|
|
449
|
+
kwargs,
|
|
450
|
+
stateStatus: transactionHashVariant === "latest-final" /* LATEST_FINAL */ ? "FINALIZED" /* FINALIZED */ : "ACCEPTED" /* ACCEPTED */,
|
|
451
|
+
rawReturn: args.rawReturn ?? false
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
441
455
|
const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
442
456
|
const serializedData = serialize(encodedData);
|
|
443
457
|
const senderAddress = account?.address ?? client.account?.address;
|
|
@@ -508,6 +522,36 @@ var contractActions = (client, publicClient) => {
|
|
|
508
522
|
}
|
|
509
523
|
};
|
|
510
524
|
};
|
|
525
|
+
var _localnetReadContract = async ({
|
|
526
|
+
client,
|
|
527
|
+
args
|
|
528
|
+
}) => {
|
|
529
|
+
const {
|
|
530
|
+
account,
|
|
531
|
+
address,
|
|
532
|
+
functionName,
|
|
533
|
+
args: callArgs,
|
|
534
|
+
kwargs,
|
|
535
|
+
stateStatus = "ACCEPTED" /* ACCEPTED */
|
|
536
|
+
} = args;
|
|
537
|
+
const encodedData = encode(makeCalldataObject(functionName, callArgs, kwargs));
|
|
538
|
+
const serializedData = serializeOne(encodedData);
|
|
539
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
540
|
+
const requestParams = {
|
|
541
|
+
to: address,
|
|
542
|
+
from: senderAddress,
|
|
543
|
+
data: serializedData
|
|
544
|
+
};
|
|
545
|
+
const result = await client.request({
|
|
546
|
+
method: "eth_call",
|
|
547
|
+
params: [requestParams, stateStatus == "FINALIZED" /* FINALIZED */ ? "finalized" : "latest"]
|
|
548
|
+
});
|
|
549
|
+
if (args.rawReturn) {
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
const resultBinary = fromHex(result, "bytes");
|
|
553
|
+
return decode(resultBinary);
|
|
554
|
+
};
|
|
511
555
|
var _sendTransaction = async ({
|
|
512
556
|
client,
|
|
513
557
|
publicClient,
|
package/package.json
CHANGED
package/src/contracts/actions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as calldata from "@/abi/calldata";
|
|
2
|
-
import {serialize} from "@/abi/transactions";
|
|
2
|
+
import {serialize, serializeOne} from "@/abi/transactions";
|
|
3
3
|
import {localnet} from "@/chains/localnet";
|
|
4
4
|
import {
|
|
5
5
|
Account,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
CalldataEncodable,
|
|
10
10
|
Address,
|
|
11
11
|
TransactionHashVariant,
|
|
12
|
+
TransactionStatus,
|
|
12
13
|
} from "@/types";
|
|
13
14
|
import {fromHex, toHex, zeroAddress, encodeFunctionData, PublicClient, parseEventLogs} from "viem";
|
|
14
15
|
|
|
@@ -90,6 +91,26 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
90
91
|
leaderOnly = false,
|
|
91
92
|
transactionHashVariant = TransactionHashVariant.LATEST_FINAL,
|
|
92
93
|
} = args;
|
|
94
|
+
|
|
95
|
+
// TODO: remove this once DXP-298 is merged
|
|
96
|
+
if (client.chain.id === localnet.id) {
|
|
97
|
+
return _localnetReadContract({
|
|
98
|
+
client,
|
|
99
|
+
args: {
|
|
100
|
+
account,
|
|
101
|
+
address,
|
|
102
|
+
functionName,
|
|
103
|
+
args: callArgs,
|
|
104
|
+
kwargs,
|
|
105
|
+
stateStatus:
|
|
106
|
+
transactionHashVariant === TransactionHashVariant.LATEST_FINAL
|
|
107
|
+
? TransactionStatus.FINALIZED
|
|
108
|
+
: TransactionStatus.ACCEPTED,
|
|
109
|
+
rawReturn: args.rawReturn ?? false,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
const encodedData = [calldata.encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
94
115
|
const serializedData = serialize(encodedData);
|
|
95
116
|
|
|
@@ -179,6 +200,51 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
179
200
|
},
|
|
180
201
|
};
|
|
181
202
|
};
|
|
203
|
+
// TODO: remove this once DXP-298 is merged
|
|
204
|
+
const _localnetReadContract = async ({
|
|
205
|
+
client,
|
|
206
|
+
args,
|
|
207
|
+
}: {
|
|
208
|
+
client: GenLayerClient<GenLayerChain>;
|
|
209
|
+
args: {
|
|
210
|
+
account?: Account;
|
|
211
|
+
address: Address;
|
|
212
|
+
functionName: string;
|
|
213
|
+
args?: CalldataEncodable[];
|
|
214
|
+
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
215
|
+
stateStatus?: TransactionStatus;
|
|
216
|
+
rawReturn?: boolean;
|
|
217
|
+
};
|
|
218
|
+
}) => {
|
|
219
|
+
const {
|
|
220
|
+
account,
|
|
221
|
+
address,
|
|
222
|
+
functionName,
|
|
223
|
+
args: callArgs,
|
|
224
|
+
kwargs,
|
|
225
|
+
stateStatus = TransactionStatus.ACCEPTED,
|
|
226
|
+
} = args;
|
|
227
|
+
const encodedData = calldata.encode(makeCalldataObject(functionName, callArgs, kwargs));
|
|
228
|
+
const serializedData = serializeOne(encodedData);
|
|
229
|
+
|
|
230
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
231
|
+
|
|
232
|
+
const requestParams = {
|
|
233
|
+
to: address,
|
|
234
|
+
from: senderAddress,
|
|
235
|
+
data: serializedData,
|
|
236
|
+
};
|
|
237
|
+
const result = await client.request({
|
|
238
|
+
method: "eth_call",
|
|
239
|
+
params: [requestParams, stateStatus == TransactionStatus.FINALIZED ? "finalized" : "latest"],
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (args.rawReturn) {
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
const resultBinary = fromHex(result, "bytes");
|
|
246
|
+
return calldata.decode(resultBinary) as any;
|
|
247
|
+
};
|
|
182
248
|
|
|
183
249
|
const _sendTransaction = async ({
|
|
184
250
|
client,
|