From 6528582b5ccc7f650d0cbd7ed9eb85ba1e13af1d Mon Sep 17 00:00:00 2001 From: Andres Aiello Date: Mon, 29 Jan 2024 12:00:55 -0300 Subject: [PATCH] feat: implement feature to disable invitation --- .../contracts/zeta-points/InvitationManager.sol | 14 +++++++++++++- packages/zevm-app-contracts/test/Disperse.spec.ts | 11 ++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/zevm-app-contracts/contracts/zeta-points/InvitationManager.sol b/packages/zevm-app-contracts/contracts/zeta-points/InvitationManager.sol index 50f43173..055b802d 100644 --- a/packages/zevm-app-contracts/contracts/zeta-points/InvitationManager.sol +++ b/packages/zevm-app-contracts/contracts/zeta-points/InvitationManager.sol @@ -8,6 +8,10 @@ contract InvitationManager { bytes32 r; bytes32 s; } + + // Indicate if invitation is still available. The default value is true. + mapping(address => bool) public invitationEnabled; + // Records the timestamp when a particular user gets verified. mapping(address => uint256) public userVerificationTimestamps; @@ -24,6 +28,7 @@ contract InvitationManager { mapping(address => mapping(uint256 => uint256)) public totalInvitesByInviterByDay; error UserAlreadyVerified(); + error UserNotVerified(); error UnrecognizedInvitation(); error IndexOutOfBounds(); error CanNotInviteYourself(); @@ -41,6 +46,12 @@ contract InvitationManager { function markAsVerified() external { _markAsVerified(msg.sender); + invitationEnabled[msg.sender] = true; + } + + function udpateInvitationStatus(bool value) external { + if (userVerificationTimestamps[msg.sender] == 0) revert UserNotVerified(); + invitationEnabled[msg.sender] = value; } function hasBeenVerified(address userAddress) external view returns (bool) { @@ -61,7 +72,8 @@ contract InvitationManager { function confirmAndAcceptInvitation(address inviter, Signature calldata signature) external { if (inviter == msg.sender) revert CanNotInviteYourself(); - if (userVerificationTimestamps[inviter] == 0) revert UnrecognizedInvitation(); + if (!invitationEnabled[inviter]) revert UnrecognizedInvitation(); + _verifySignature(inviter, signature); acceptedInvitationsTimestamp[inviter][msg.sender] = block.timestamp; diff --git a/packages/zevm-app-contracts/test/Disperse.spec.ts b/packages/zevm-app-contracts/test/Disperse.spec.ts index 20b7ca2c..0b9e5c2f 100644 --- a/packages/zevm-app-contracts/test/Disperse.spec.ts +++ b/packages/zevm-app-contracts/test/Disperse.spec.ts @@ -1,6 +1,7 @@ import { parseUnits } from "@ethersproject/units"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { expect } from "chai"; +import { parseEther } from "ethers/lib/utils"; import { ethers, network } from "hardhat"; import { Disperse, Disperse__factory, MockZRC20, MockZRC20__factory } from "../typechain-types"; @@ -26,15 +27,19 @@ describe("Disperse tests", () => { const amount = parseUnits("10"); const balance0 = await ethers.provider.getBalance(accounts[0].address); const balance1 = await ethers.provider.getBalance(accounts[1].address); - await disperseContract.disperseEther([accounts[0].address, accounts[1].address], [amount, amount.mul(2)], { + + const bigArrayAddress = new Array(500).fill(accounts[0].address); + const bigArrayAmount = new Array(500).fill(parseEther("0.01")); + + await disperseContract.disperseEther(bigArrayAddress, bigArrayAmount, { value: amount.mul(3), }); const balance0After = await ethers.provider.getBalance(accounts[0].address); const balance1After = await ethers.provider.getBalance(accounts[1].address); - expect(balance0After.sub(balance0)).to.be.eq(amount); - expect(balance1After.sub(balance1)).to.be.eq(amount.mul(2)); + expect(balance0After.sub(balance0)).to.be.eq(parseEther("0.01").mul("500")); + expect(balance1After.sub(balance1)).to.be.eq(0); }); it("Should disperse ETH with surplus", async () => {