Skip to content

Commit

Permalink
Merge pull request #15 from The-Poolz/issue_8
Browse files Browse the repository at this point in the history
add new Dispenser event
  • Loading branch information
YouStillAlive authored Mar 25, 2024
2 parents da09f9a + 313b8a8 commit 4b37e68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
13 changes: 7 additions & 6 deletions contracts/DispenserProvider.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./DispenserModifiers.sol";
import "./DispenserRequires.sol";

contract DispenserProvider is DispenserModifiers {
contract DispenserProvider is DispenserRequires {
constructor(ILockDealNFT _lockDealNFT) DealProvider(_lockDealNFT) {
name = "DispenserProvider";
}
Expand All @@ -17,12 +17,13 @@ contract DispenserProvider is DispenserModifiers {
)
external
validProviderId(poolId)
isCallerApproved(poolId, owner)
isValidTime(validUntil)
isAlreadyTaken(poolId, owner)
{
_isCallerApproved(poolId, owner);
_isValidTime(validUntil);
_isAlreadyTaken(poolId, owner);
_isValidSignature(poolId, validUntil, owner, data, signature);
_handleSimpleNFTs(poolId, owner, data);
uint256 amountTaken = _handleSimpleNFTs(poolId, owner, data);
emit TokensDispensed(poolId, owner, amountTaken, poolIdToAmount[poolId]);
}

function supportsInterface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@ pragma solidity ^0.8.0;

import "./DispenserInternal.sol";

abstract contract DispenserModifiers is DispenserInternal {
modifier isCallerApproved(uint256 poolId, address owner) {
_isCallerApproved(poolId, owner);
_;
}

modifier isValidTime(uint256 validUntil) {
_isValidTime(validUntil);
_;
}

modifier isAlreadyTaken(uint256 poolId, address owner) {
_isAlreadyTaken(poolId, owner);
_;
}

// Internal functions for gas optimization
abstract contract DispenserRequires is DispenserInternal {
function _isCallerApproved(uint256 poolId, address owner) internal view {
require(
msg.sender == owner ||
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IDispenserProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.0;
import "@poolzfinance/poolz-helper-v2/contracts/interfaces/ISimpleProvider.sol";

interface IDispenserProvider is ISimpleProvider {
event TokensDispensed(uint256 poolId, address user, uint256 amountTaken, uint256 leftAmount);

struct Builder {
ISimpleProvider simpleProvider;
uint256[] params;
Expand Down
8 changes: 8 additions & 0 deletions test/DispenserProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ describe("Dispenser Provider tests", function () {
).to.be.revertedWith("amount must be greater than 0")
})

it("should emit TokensDispensed event", async () => {
const signatureData = [poolId, validTime, user.address, userData]
const signature = await createSignature(signer, signatureData)
await expect(dispenserProvider.connect(user).dispenseLock(poolId, validTime, user.address, usersData, signature))
.to.emit(dispenserProvider, "TokensDispensed")
.withArgs(poolId, user.address, amount.div(2), amount.div(2))
})

it("should support IERC165 interface", async () => {
expect(await dispenserProvider.supportsInterface('0x01ffc9a7')).to.equal(true)
})
Expand Down

0 comments on commit 4b37e68

Please sign in to comment.