@zk-kit/lazytower.sol

0.0.1 • Public • Published

LazyTower (Solidity)

LazyTower Solidity libraries.

NPM license NPM version Downloads Linter eslint Code style prettier

❗ WARNING

This library has not been audited.

Libraries:

✔️ LazyTowerHashChain (Poseidon)


🛠 Install

npm or yarn

Install the @zk-kit/lazytower.sol package with npm:

npm i @zk-kit/lazytower.sol --save

or yarn:

yarn add @zk-kit/lazytower.sol

📜 Usage

Importing and using the library

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

import "../LazyTowerHashChain.sol";

contract LazyTowerHashChainTest {
    using LazyTowerHashChain for LazyTowerHashChainData;

    event Add(uint256 item);

    // map for multiple test cases
    mapping(bytes32 => LazyTowerHashChainData) public towers;

    function add(bytes32 _towerId, uint256 _item) external {
        towers[_towerId].add(_item);
        emit Add(_item);
    }

    function getDataForProving(bytes32 _towerId) external view returns (uint256, uint256[] memory, uint256) {
        return towers[_towerId].getDataForProving();
    }
}

Creating an Hardhat task to deploy the contract

import { Contract } from "ethers"
import { task, types } from "hardhat/config"

task("deploy:lazytower-test", "Deploy a LazyTowerHashChainTest contract")
    .addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
    .setAction(async ({ logs }, { ethers }): Promise<Contract> => {
        const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3")
        const PoseidonT3 = await PoseidonT3Factory.deploy()

        if (logs) {
            console.info(`PoseidonT3 library has been deployed to: ${PoseidonT3.address}`)
        }

        const LazyTowerLibFactory = await ethers.getContractFactory("LazyTowerHashChain", {
            libraries: {
                PoseidonT3: PoseidonT3.address
            }
        })
        const lazyTowerLib = await LazyTowerLibFactory.deploy()

        await lazyTowerLib.deployed()

        if (logs) {
            console.info(`LazyTowerHashChain library has been deployed to: ${lazyTowerLib.address}`)
        }

        const ContractFactory = await ethers.getContractFactory("LazyTowerHashChainTest", {
            libraries: {
                LazyTowerHashChain: lazyTowerLib.address
            }
        })

        const contract = await ContractFactory.deploy()

        await contract.deployed()

        if (logs) {
            console.info(`Test contract has been deployed to: ${contract.address}`)
        }

        return contract
    })

Contacts

Developers

Package Sidebar

Install

npm i @zk-kit/lazytower.sol

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

6.68 kB

Total Files

4

Last publish

Collaborators

  • sripwoud
  • njofce
  • akinovak
  • cedoor