Coder Social home page Coder Social logo

parallel-signer's Introduction

README.md

Project Description

This project is designed to ...

Initialization Steps

To initialize the project, follow these steps:

  1. Set up the network configuration in the .env file:
POLYGON_WEB3_URL=""
POLYGON_WEB3_PRIVATE_KEY=""

Note: The POLYGON_WEB3_URL should be obtained from chainlist.org for the Polygon testnet RPC node. The POLYGON_WEB3_PRIVATE_KEY are the private keys required for deploying test contracts and executing test case. You can export the private keys from Metamask.

  1. Obtain the gas token for the Polygon testnet.

  2. Execute the following command to deploy the test contracts:

    npx hardhat run tests/deploy.ts

How to Use

Call the normal batch execution function

export async function populateFun1(requests: Request[]): Promise<{
  to: string;
  data: string;
  value?: BigNumberish;
  gasLimit: BigNumberish;
  maxFeePerGas?: string;
  maxPriorityFeePerGas?: string;
  gasPrice?: string;
}> {
  const artifact = await artifacts.readArtifact("TransferMulticall");
  const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode);
  const calldata = factory.interface.encodeFunctionData("batchTrasnfer", [
    requests.map((v) => v.functionData),
  ]);

  return {
    to: TransferMulticall_POLYGON_ADDRESS,
    data: calldata,
    value: 0,
    gasLimit: BigNumber.from("100000").mul(requests.length),
    maxFeePerGas: null,
    maxPriorityFeePerGas: null,
    gasPrice: parseUnits("10", "gwei").toString(),
  };
}
export function buildFunctionData1(amount: string): string {
  return parseUnits(amount, "ether").toString();
}

A contract that supports the multicall method

export async function populateFun2(requests: Request[]): Promise<{
  to: string;
  data: string;
  value?: BigNumberish;
  gasLimit: BigNumberish;
  maxFeePerGas?: string;
  maxPriorityFeePerGas?: string;
  gasPrice?: string;
}> {
  const factory = (await ethers.getContractFactoryFromArtifact(
    await artifacts.readArtifact("TransferMulticall")
  )) as TransferMulticall__factory;
  const calldata = factory.interface.encodeFunctionData("multicall", [
    requests.map((v) => v.functionData),
  ]);

  return {
    to: TransferMulticall_POLYGON_ADDRESS,
    data: calldata,
    value: 0,
    gasLimit: BigNumber.from("100000").mul(requests.length),
    maxFeePerGas: null,
    maxPriorityFeePerGas: null,
    gasPrice: parseUnits("10", "gwei").toString(),
  };
}
export async function buildFunctionData2(
  to: string,
  amount: BigNumber
): Promise<string> {
  const factory = (await ethers.getContractFactoryFromArtifact(
    await artifacts.readArtifact("TransferMulticall")
  )) as TransferMulticall__factory;
  return factory.interface.encodeFunctionData("accept", [to, amount]);
}

parallel-signer's People

Contributors

zklinkjohn avatar zklinklabs avatar zktyral avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.