genlayer-js 0.9.5 → 0.11.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.
@@ -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-CWYHlYb1.cjs';
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';
@@ -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-CjM-U5oN.js';
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.9.5",
4
+ "version": "0.11.0",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1,3 +1,4 @@
1
1
  // src/chains/index.ts
2
2
  export {localnet} from "./localnet";
3
+ export {studionet} from "./studionet";
3
4
  export {testnetAsimov} from "./testnetAsimov";
@@ -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
- return _sendTransaction({
140
+ const senderAccount = account || client.account;
141
+ const encodedData = _encodeAddTransactionData({
141
142
  client,
142
- publicClient,
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
- return _sendTransaction({
178
+ const senderAccount = account || client.account;
179
+ const encodedData = _encodeAddTransactionData({
173
180
  client,
174
- publicClient: publicClient,
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 _sendTransaction = async ({
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
- publicClient,
221
+ senderAccount,
187
222
  recipient,
188
223
  data,
189
- senderAccount,
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
- value?: bigint;
200
- }) => {
201
- if (!senderAccount) {
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
- senderAccount.address,
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: senderAccount.address});
279
+ const nonce = await client.getCurrentNonce({address: validatedSenderAccount.address});
224
280
  const transactionRequest = await client.prepareTransactionRequest({
225
- account: senderAccount,
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 ?? 0n,
286
+ value: value,
231
287
  });
232
288
 
233
- if (senderAccount?.type !== "local") {
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 (!senderAccount?.signTransaction) {
303
+ if (!validatedSenderAccount?.signTransaction) {
248
304
  throw new Error("Account does not support signTransaction");
249
305
  }
250
306
 
251
- const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
307
+ const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
252
308
 
253
309
  const txHash = await client.sendRawTransaction({serializedTransaction: serializedTransaction});
254
310
 
@@ -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
  };