@poolzfinance/dispenser-provider
v1.1.2
Published
[](https://github.com/The-Poolz/LockDealNFT.DispenserProvider/actions/workflows/node.js.yml) [
external
returns (uint256 poolId);Testnet example call: BSC Testnet Transaction
Function selector: 0x14877c38
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 receiver 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.
To call this function, caller must have the pool owner's signature, be the recipient or an approved representative of the recipient, or the pool owner can call it on behalf of a specific user. Upon successful execution, the recipient will receive locked tokens from simple providers.
/// @notice Dispenses tokens from a locked pool based on provided data and signature.
/// If the pool owner intends to dispense tokens to himself, using the Withdraw
/// or Split followed by Withdraw option is recommended.
/// This function supports dispensing tokens to any address specified by the owner.
/// The signature provided is unique and can be used only once
/// @dev Validates the caller's approval, the signature, the availability of tokens, and the lock time before dispensing.
/// If successful, it dispenses the tokens and emits an event.
/// @param message The message struct containing the pool ID, receiver address, data, and validUntil timestamp.
/// @param signature The signature provided by the pool owner to validate the message.
function dispenseLock(
MessageStruct calldata message,
bytes calldata signature
)EIP-712 JSON signature format: https://github.com/The-Poolz/LockDealNFT.DispenserProvider/issues/60#issuecomment-2582469583
Testnet example call: BSC Testnet Transaction
Function selector: 0xad43114e
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: IDispenserProvider.MessageStructStruct = {
poolId: poolId,
receiver: await receiver.getAddress(),
validUntil: validTime,
data: usersData,
}
const signature = await createEIP712Signature(
poolId,
await receiver.getAddress(),
validTime,
signer,
await dispenserProvider.getAddress(),
usersData
)
await dispenserProvider.dispenseLock(signatureData, signature)
async function createEIP712Signature(
poolId: bigint,
receiver: string,
validUntil: number,
signer: SignerWithAddress,
contractAddress: string,
data: IDispenserProvider.BuilderStruct[]
): Promise<string> {
const domain = {
name: "DispenserProvider",
version: "1",
chainId: (await ethers.provider.getNetwork()).chainId,
verifyingContract: contractAddress,
}
const types = {
Builder: [
{ name: "simpleProvider", type: "address" },
{ name: "params", type: "uint256[]" },
],
MessageStruct: [
{ name: "poolId", type: "uint256" },
{ name: "receiver", type: "address" },
{ name: "validUntil", type: "uint256" },
{ name: "data", type: "Builder[]" },
],
}
const value = {
data: data,
poolId: poolId.toString(),
receiver: receiver,
validUntil: validUntil,
}
// Use signTypedData to create the signature
return await signer.signTypedData(domain, types, value)
}License
The-Poolz Contracts is released under the MIT License.
