npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@poolzfinance/dispenser-provider

v1.0.3

Published

[![Build and Test](https://github.com/The-Poolz/LockDealNFT.DispenserProvider/actions/workflows/node.js.yml/badge.svg)](https://github.com/The-Poolz/LockDealNFT.DispenserProvider/actions/workflows/node.js.yml) [![codecov](https://codecov.io/gh/The-Poolz/

Downloads

118

Readme

LockDealNFT.DispenserProvider

Build and Test codecov CodeFactor License

DispenserProvider contract is part of a system designed to manage and dispense tokens from a pool in response to approved requests. It allows creating token pools and locking tokens for distribution according to predefined conditions

Navigation

Installation

Install the packages:

npm i

Compile contracts:

npx hardhat compile

Run tests:

npx hardhat test

Run coverage:

npx hardhat coverage

Deploy:

npx truffle dashboard
npx hardhat run ./scripts/deploy.ts --network truffleDashboard

Overview

The DispenserProvider contract manages token dispensing in collaboration with LockDealNFT, Simple Providers, and VaultManager contracts. It creates token pools, locks tokens, and distributes them based on predefined rules set by these providers.

Key Features

  • Token Pool Creation: Allows the creation of token pools, storing tokens for later distribution.
  • Token Dispensing: Locks tokens for a specified recipient using a signature-based authorization.
  • Integration with Multiple Providers: Works with other provider contracts like LockDealProvider, DealProvider, and TimedDealProvider.
  • Events and Notifications: Emits events for tracking token distributions and errors.

Contracts diagram

classDiagram

Create Dispenser Pool

createNewPool function is used to create a new token pool with specific parameters. This function accepts an array of addresses, an array of pool parameters, and a signature from the pool owner. It interacts with the LockDealNFT contract to mint and transfer the tokens, register the pool.

    /**
     * @dev Creates a new pool with the specified parameters.
     * @param addresses[0] The address of the pool owner.
     * @param addresses[1] The address of the token associated with the pool.
     * @param params An array of pool parameters.
     * @param signature The signature of the pool owner.
     * @return poolId The ID of the newly created pool.
     */
    function createNewPool(
        address[] calldata addresses,
        uint256[] calldata params,
        bytes calldata signature
    )
        external
        returns (uint256 poolId);

Typescript example

To interact with the createNewPool function from a TypeScript script, you can use the following example. Ensure you have installed the necessary dependencies such as ethers, hardhat, and appropriate network configuration.

import { ethers } from "hardhat"

const amount = ethers.parseUnits("10", 18)
const tokenAddress = await token.getAddress()
const addresses = [await signer.getAddress(), tokenAddress]
const params = [amount]
const nounce = await vaultManager.nonces(fromAddress)
const creationSignature = await ethers.provider
    .getSigner()
    .signMessage(
        ethers.utils.arrayify(
            ethers.utils.solidityKeccak256(["address", "uint256", "uint256"], [tokenAddress, amount, nounce])
        )
    )
await token.approve(await vaultManager.getAddress(), amount)
await dispenserProvider.createNewPool([ownerAddress, tokenAddress], params, creationSignature)

Dispense Lock

dispenseLock function is responsible for dispensing tokens from a pool to the specified owner based on predefined rules. It ensures that the caller is authorized, the request is valid, and that the signature provided matches the expected one. This function handles simple NFTs and emits an event when tokens are dispensed.

    /**
     * @dev Dispenses tokens from the pool to the specified owner.
     * @param poolId The ID of the pool from which tokens are dispensed.
     * @param validUntil The time until which the dispensation is valid.
     * @param owner The address of the pool owner receiving the dispensed tokens.
     * @param data An array of Builder structs containing the details of the NFTs to be handled.
     * @param signature The signature of the pool owner authorizing the dispensation.
     */
function dispenseLock(
        uint256 poolId,
        uint256 validUntil,
        address owner,
        Builder[] calldata data,
        bytes calldata signature
    ) external;

TypeScript Example

To interact with the dispenseLock function in a TypeScript script, you can use the following example. Ensure that you have the necessary dependencies installed (ethers, hardhat, etc.), and adjust network configurations accordingly.

import { ethers } from "hardhat"

const amount = ethers.parseUnits("10", 18)
const poolId = 1 // Example pool ID
const ONE_DAY = 86400
const validTime = (await time.latest()) + ONE_DAY
let userData: IDispenserProvider.BuilderStruct = {
    simpleProvider: await lockProvider.getAddress(), // or any simple provider.
    params: [amount / 2n, validTime],
}
let usersData: IDispenserProvider.BuilderStruct[] = [userData]
const signatureData = [poolId, validTime, await user.getAddress(), userData]
const signature = await createSignature(signer, signatureData)
await dispenserProvider.dispenseLock(poolId, validTime, await user.getAddress(), usersData, signature)

async function createSignature(signer: SignerWithAddress, data: any[]): Promise<string> {
    const types: string[] = []
    const values: any[] = []
    for (const element of data) {
        if (typeof element === "string") {
            types.push("address")
            values.push(element)
        } else if (typeof element === "object" && Array.isArray(element)) {
            types.push("uint256[]")
            values.push(element)
        } else if (typeof element === "number" || typeof element === "bigint") {
            types.push("uint256")
            values.push(element)
        } else if (typeof element === "object" && !Array.isArray(element)) {
            types.push("address")
            values.push(element.simpleProvider)
            types.push("uint256[]")
            values.push(element.params)
        }
    }
    const packedData = ethers.solidityPackedKeccak256(types, values)
    return signer.signMessage(ethers.getBytes(packedData))
}

License

The-Poolz Contracts is released under the MIT License.