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.
- package/CHANGELOG.md +14 -0
- package/dist/chains/index.cjs +4 -2
- package/dist/chains/index.d.cts +1 -1
- package/dist/chains/index.d.ts +1 -1
- package/dist/chains/index.js +3 -1
- package/dist/{chunk-4FVQ3G7J.js → chunk-565IJBV4.js} +4022 -8
- package/dist/{chunk-SMCXL465.cjs → chunk-N65Y4TC3.cjs} +4021 -7
- package/dist/{index-CWYHlYb1.d.cts → index-BhRfI25e.d.cts} +4 -0
- package/dist/{index-B52a6DSr.d.cts → index-Bw-kn7CF.d.cts} +5 -2
- package/dist/{index-DNvW8slT.d.ts → index-DCzgdyMa.d.ts} +5 -2
- package/dist/{index-CjM-U5oN.d.ts → index-dnt5ldCd.d.ts} +4 -0
- package/dist/index.cjs +99 -4066
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +74 -4041
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/chains/index.ts +1 -0
- package/src/contracts/actions.ts +90 -34
- package/src/types/clients.ts +4 -0
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/chains/index.ts
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
|
@@ -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
|
};
|