mirror of
https://github.com/vacp2p/linea-monorepo.git
synced 2026-01-09 07:28:05 -05:00
* feat: split postman and sdk * fix: update postman client and sendMessage script * fix: clean the sdk * fix: update sdk dependencies * fix: remove .env.sample file * fix: remove testing helpers from the build * fix: update gas provider in linea sdk and update postman client * fix: update postman dependencies * fix: update postman dockerfile and fix tests imports and types * fix: remove unused code in the sdk + move typechain folder * fix: remove unused code + fix imports in postman * fix: pnpm lock file issue * fix: import issue * fix: case sensitive file issue * fix: update sdk fees options and update exports * fix: remove postman unused code and adjust imports and tests * fix: update contracts abis + clean error parsing * fix: update postman based on new SDk changes * add readme + remove unused interface in postman * fix: rename Base.ts file to BaseError.ts * fix: rename Base.ts file to BaseError.ts in postman * chore: update readme for the postman * fix: rename maxFeePerGas to maxFeePerGasCap * fix: update DefaultGasProvider fees check * fix: default gas provider test issue * fix: update main ci filter * fix: issue in default gas provider
110 lines
2.9 KiB
TypeScript
110 lines
2.9 KiB
TypeScript
import { ContractTransactionReceipt, Overrides, JsonRpcProvider, Wallet } from "ethers";
|
|
import { config } from "dotenv";
|
|
import yargs from "yargs";
|
|
import { hideBin } from "yargs/helpers";
|
|
import { L2MessageService, L2MessageService__factory } from "@consensys/linea-sdk";
|
|
import { SendMessageArgs } from "./types";
|
|
import { sanitizeAddress, sanitizePrivKey } from "./cli";
|
|
|
|
config();
|
|
|
|
const argv = yargs(hideBin(process.argv))
|
|
.option("rpc-url", {
|
|
describe: "Rpc url",
|
|
type: "string",
|
|
demandOption: true,
|
|
})
|
|
.option("priv-key", {
|
|
describe: "Signer private key",
|
|
type: "string",
|
|
demandOption: true,
|
|
coerce: sanitizePrivKey("priv-key"),
|
|
})
|
|
.option("contract-address", {
|
|
describe: "Smart contract address",
|
|
type: "string",
|
|
demandOption: true,
|
|
coerce: sanitizeAddress("smc-address"),
|
|
})
|
|
.option("to", {
|
|
describe: "Destination address",
|
|
type: "string",
|
|
demandOption: true,
|
|
coerce: sanitizeAddress("to"),
|
|
})
|
|
.option("fee", {
|
|
describe: "Fee passed to send message function",
|
|
type: "string",
|
|
})
|
|
.option("value", {
|
|
describe: "Value passed to send message function",
|
|
type: "string",
|
|
})
|
|
.option("calldata", {
|
|
describe: "Encoded message calldata",
|
|
type: "string",
|
|
demandOption: true,
|
|
})
|
|
.option("number-of-message", {
|
|
describe: "Number of messages to send",
|
|
type: "number",
|
|
demandOption: true,
|
|
})
|
|
.parseSync();
|
|
|
|
const sendMessage = async (
|
|
contract: L2MessageService,
|
|
args: SendMessageArgs,
|
|
overrides: Overrides = {},
|
|
): Promise<ContractTransactionReceipt | null> => {
|
|
const tx = await contract.sendMessage(args.to, args.fee, args.calldata, overrides);
|
|
return await tx.wait();
|
|
};
|
|
|
|
const sendMessages = async (
|
|
contract: L2MessageService,
|
|
signer: Wallet,
|
|
numberOfMessages: number,
|
|
args: SendMessageArgs,
|
|
overrides?: Overrides,
|
|
) => {
|
|
let nonce = await signer.getNonce();
|
|
const sendMessagePromises: Promise<ContractTransactionReceipt | null>[] = [];
|
|
|
|
for (let i = 0; i < numberOfMessages; i++) {
|
|
sendMessagePromises.push(
|
|
sendMessage(contract, args, {
|
|
...overrides,
|
|
nonce,
|
|
}),
|
|
);
|
|
nonce++;
|
|
}
|
|
|
|
await Promise.all(sendMessagePromises);
|
|
};
|
|
|
|
const main = async (args: typeof argv) => {
|
|
const provider = new JsonRpcProvider(args.rpcUrl);
|
|
const signer = new Wallet(args.privKey, provider);
|
|
|
|
const functionArgs: SendMessageArgs & Overrides = {
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
to: args.to,
|
|
fee: BigInt(args.fee!),
|
|
calldata: args.calldata,
|
|
value: args.value,
|
|
};
|
|
|
|
const l2MessageService = L2MessageService__factory.connect(args.contractAddress, signer) as L2MessageService;
|
|
|
|
await sendMessages(l2MessageService, signer, args.numberOfMessage, functionArgs, { value: args.value });
|
|
};
|
|
|
|
main(argv)
|
|
.then(() => process.exit(0))
|
|
.catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|