Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add params to IR factory #198

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

contract InstantRewards is Ownable2Step, Pausable, ReentrancyGuard, EIP712 {
contract InstantRewards is Ownable, Pausable, ReentrancyGuard, EIP712 {
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
bytes32 private constant CLAIM_TYPEHASH =
keccak256("Claim(address to,uint256 sigExpiration,bytes32 taskId,uint256 amount)");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
import "./InstantRewardsV2.sol";

contract InstantRewardsFactory is Ownable2Step {
contract InstantRewardsFactory is Ownable {
bool public allowPublicCreation = false;

error AccessDenied();
Expand All @@ -13,7 +13,7 @@ contract InstantRewardsFactory is Ownable2Step {
error StartTimeInPast();
error EndTimeBeforeStart();

event InstantRewardsCreated(address indexed instantRewards, address indexed owner);
event InstantRewardsCreated(address indexed instantRewards, address indexed owner, string name);

constructor(address owner) Ownable() {
transferOwnership(owner);
Expand All @@ -27,7 +27,10 @@ contract InstantRewardsFactory is Ownable2Step {
address signerAddress,
uint256 start,
uint256 end,
string memory name
string memory name,
string memory promoUrl,
string memory avatarUrl,
string memory description
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
) external returns (address) {
if (signerAddress == address(0)) revert InvalidSignerAddress();
if (bytes(name).length == 0) revert EmptyName();
Expand All @@ -37,9 +40,17 @@ contract InstantRewardsFactory is Ownable2Step {
bool isOwner = owner() == msg.sender;
if (!allowPublicCreation && !isOwner) revert AccessDenied();

InstantRewardsV2 instantRewards = new InstantRewardsV2(signerAddress, owner(), start, end, name);
instantRewards.transferOwnership(owner());
emit InstantRewardsCreated(address(instantRewards), owner());
InstantRewardsV2 instantRewards = new InstantRewardsV2(
signerAddress,
owner(),
start,
end,
name,
promoUrl,
avatarUrl,
description
);
emit InstantRewardsCreated(address(instantRewards), owner(), name);
return address(instantRewards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ contract InstantRewardsV2 is InstantRewards {

uint256 public start;
uint256 public end;
string public promoUrl;
string public avatarUrl;
string public description;
andresaiello marked this conversation as resolved.
Show resolved Hide resolved

event TimeframeUpdated(uint256 start, uint256 end);

Expand All @@ -20,13 +23,19 @@ contract InstantRewardsV2 is InstantRewards {
address owner,
uint256 start_,
uint256 end_,
string memory name_
string memory name_,
string memory promoUrl_,
string memory avatarUrl_,
string memory description_
) InstantRewards(signerAddress_, owner) {
if (signerAddress_ == address(0)) revert InvalidAddress();
if (start_ > end_) revert InvalidTimeframe();
start = start_;
end = end_;
name = name_;
promoUrl = promoUrl_;
avatarUrl = avatarUrl_;
description = description_;
}

function isActive() public view returns (bool) {
Expand All @@ -48,7 +57,6 @@ contract InstantRewardsV2 is InstantRewards {
}

function withdraw(address wallet, uint256 amount) public override onlyOwner {
if (isActive()) revert InstantRewardStillActive();
super.withdraw(wallet, amount);
}
}
8 changes: 5 additions & 3 deletions packages/zevm-app-contracts/data/addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"ProofOfLiveness": "0x981EB6fD19717Faf293Fba0cBD05C6Ac97b8C808",
"TimelockController": "0x44139C2150c11c25f517B8a8F974b59C82aEe709",
"ZetaXPGov": "0x854032d484aE21acC34F36324E55A8080F21Af12",
"invitationManagerV2": "0xb80f6360194Dd6B47B80bd8730b3dBb05a39e723"
"invitationManagerV2": "0xb80f6360194Dd6B47B80bd8730b3dBb05a39e723",
"InstantRewardsFactory": "0x3A557fe83FD734f21DD35E98f546B9706d486F55"
},
"zeta_mainnet": {
"disperse": "0x23ce409Ea60c3d75827d04D9db3d52F3af62e44d",
Expand All @@ -22,8 +23,9 @@
"invitationManager": "0x3649C03C472B698213926543456E9c21081e529d",
"withdrawERC20": "0xa349B9367cc54b47CAb8D09A95836AE8b4D1d84E",
"ZetaXP": "0x9A4e8bB5FFD8088ecF1DdE823e97Be8080BD38cb",
"InstantRewards": "0x018412ec1D5bBb864eAe0A4BECaa683052890238",
"ProofOfLiveness": "0x327c9837B183e69C522a30E6f91A42c86e057432"
"InstantRewards": "0xfD5dcBf68c81274B48593Cb4b0322e965741392b",
"ProofOfLiveness": "0x327c9837B183e69C522a30E6f91A42c86e057432",
"InstantRewardsFactory": "0xAf5693bBC958e442462F411F46421e389c7A8602"
}
}
}
11 changes: 9 additions & 2 deletions packages/zevm-app-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const config: HardhatUserConfig = {
chainId: 7001,
network: "zeta_testnet",
urls: {
apiURL: "https://zetachain-athens-3.blockscout.com/api",
browserURL: "https://zetachain-athens-3.blockscout.com",
apiURL: "https://zetachain-testnet.blockscout.com/api",
browserURL: "https://zetachain-testnet.blockscout.com",
},
},
],
Expand All @@ -52,6 +52,13 @@ const config: HardhatUserConfig = {
},
networks: {
...getHardhatConfigNetworks(),
zeta_mainnet: {
accounts: PRIVATE_KEYS,
chainId: 7000,
gas: "auto",
gasMultiplier: 3,
url: `https://zetachain-evm.blockpi.network/v1/rpc/public`,
},
},
solidity: {
compilers: [
Expand Down
18 changes: 13 additions & 5 deletions packages/zevm-app-contracts/scripts/explorer.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { run } from "hardhat";

export const verifyContract = async (contractAddress: string, constructorArguments: any[]) => {
export const verifyContract = async (contractAddress: string, constructorArguments: any[], contract?: string) => {
// Verification process
console.log(`Verifying contract ${contractAddress}...`);
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments,
});
if (contract) {
await run("verify:verify", {
address: contractAddress,
constructorArguments,
contract,
});
} else {
await run("verify:verify", {
address: contractAddress,
constructorArguments,
});
}
console.log("Verification successful");
} catch (error) {
console.error("Verification failed:", error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,91 @@
import { isProtocolNetworkName } from "@zetachain/protocol-contracts";
import { ethers, network } from "hardhat";

import { InstantRewardsFactory__factory } from "../../typechain-types";
import { InstantRewardsFactory, InstantRewardsFactory__factory } from "../../typechain-types";
import { instantRewards } from "../../typechain-types/contracts";
import { saveAddress } from "../address.helpers";
import { verifyContract } from "../explorer.helpers";

const networkName = network.name;

const owner = "0x1d24d94520B94B26351f6573de5ef9731c48531A";
const OWNERS = {
zeta_mainnet: "0xD7E8bD37db625a4856E056D2617C9d140dB99182",
zeta_testnet: "0x1d24d94520B94B26351f6573de5ef9731c48531A",
};

//@ts-ignore
const owner = OWNERS[networkName];
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
console.log("Owner:", owner);

const deployInstantRewardsSample = async (instantRewardsFactoryAddress: string) => {
const [deployer] = await ethers.getSigners();

const InstantRewardsFactory = new InstantRewardsFactory__factory(deployer);
const instantRewards = InstantRewardsFactory.attach(instantRewardsFactoryAddress);

// get current timestamp from ethers
const block = await ethers.provider.getBlock("latest");
const timestamp = block.timestamp;
const start = timestamp + 60 * 60 * 24 * 7; // 1 week from now
const end = start + 60 * 60 * 24 * 7 * 4; // 4 weeks from start

const params = [
owner,
start,
end,
"ZetaChain",
"https://zetachain.io",
"https://zetachain.io/logo.png",
"ZetaChain description",
];

const tx = await instantRewards.createInstantRewards(...params, {
gasLimit: 25000000,
});
andresaiello marked this conversation as resolved.
Show resolved Hide resolved

const rec = await tx.wait();

// query event InstantRewardsCreated to get the address
const event = rec.events?.find((event) => event.event === "InstantRewardsCreated");

if (!event) throw new Error("InstantRewardsCreated event not found");
//@ts-ignore
const instantRewardsAddress = event.args[0];
if (!instantRewardsAddress) throw new Error("InstantRewards address not found");
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
console.log("InstantRewards deployed to:", instantRewardsAddress);

await verifyContract(
instantRewardsAddress,
[owner, ...params],
"contracts/instant-rewards/InstantRewardsV2.sol:InstantRewardsV2"
);
};

const deployInstantRewards = async () => {
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");

const InstantRewardsFactory = (await ethers.getContractFactory(
"InstantRewardsFactory"
)) as InstantRewardsFactory__factory;
const InstantRewards = await InstantRewardsFactory.deploy(owner);
const instantRewards = await InstantRewardsFactory.deploy(owner);

await instantRewards.deployed();
andresaiello marked this conversation as resolved.
Show resolved Hide resolved

await InstantRewards.deployed();
console.log("InstantRewards deployed to:", instantRewards.address);

console.log("InstantRewards deployed to:", InstantRewards.address);
saveAddress("InstantRewardsFactory", instantRewards.address, networkName);

saveAddress("InstantRewards", InstantRewards.address, networkName);
await verifyContract(instantRewards.address, [owner]);
// await verifyContract("0xAf5693bBC958e442462F411F46421e389c7A8602", [owner]);

await verifyContract(InstantRewards.address, [owner]);
return instantRewards;
};

const main = async () => {
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name");
await deployInstantRewards();
const instantRewards = await deployInstantRewards();
await deployInstantRewardsSample(instantRewards.address);
// await deployInstantRewardsSample("0x3A557fe83FD734f21DD35E98f546B9706d486F55");
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
};

main().catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ describe("Instant Rewards V2 Contract Compatibility test", () => {
const start = (await ethers.provider.getBlock("latest")).timestamp + 1;
const end = start + 1000;

instantRewards = await instantRewardsFactory.deploy(signer.address, owner.address, start, end, "Instant Rewards");
instantRewards = await instantRewardsFactory.deploy(
signer.address,
owner.address,
start,
end,
"Instant Rewards",
"http://img.com",
"http://avatar.com",
"Description"
);

await instantRewards.deployed();
});
Expand Down Expand Up @@ -322,7 +331,7 @@ describe("Instant Rewards V2 Contract Compatibility test", () => {
expect(balanceOfUser).to.be.eq(userBalanceBefore.add(amountToWithdraw));
});

it("Should fail if try to withdraw an active IR", async () => {
it("Should be able to withdraw an active IR", async () => {
const amount = utils.parseEther("2");
const amountToWithdraw = utils.parseEther("1");
// transfer some funds to the contract
Expand All @@ -331,7 +340,6 @@ describe("Instant Rewards V2 Contract Compatibility test", () => {
value: amount,
});

const tx = instantRewards.withdraw(user.address, amountToWithdraw);
await expect(tx).to.revertedWith("InstantRewardStillActive");
await instantRewards.withdraw(user.address, amountToWithdraw);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ describe("Instant Rewards Contract test", () => {
const instantRewardsFactoryF = await ethers.getContractFactory("InstantRewardsFactory");
instantRewardsFactory = (await instantRewardsFactoryF.deploy(owner.address)) as InstantRewardsFactory;
await instantRewardsFactory.deployed();
await instantRewardsFactory.connect(owner).acceptOwnership();
});

it("Should deploy an IR instance", async () => {
const currentBlock = await ethers.provider.getBlock("latest");
const start = currentBlock.timestamp + 1000;
const end = start + 1000;
const name = "Instant Rewards";
const tx = instantRewardsFactory.connect(owner).createInstantRewards(signer.address, start, end, name);
const tx = instantRewardsFactory
.connect(owner)
.createInstantRewards(signer.address, start, end, name, "http://img.com", "http://avatar.com", "Description");
andresaiello marked this conversation as resolved.
Show resolved Hide resolved
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated");

const events = await instantRewardsFactory.queryFilter("InstantRewardsCreated");
Expand All @@ -47,7 +48,15 @@ describe("Instant Rewards Contract test", () => {
const start = currentBlock.timestamp + 1000;
const end = start + 1000;
const name = "Instant Rewards";
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name);
const tx = instantRewardsFactory.createInstantRewards(
signer.address,
start,
end,
name,
"http://img.com",
"http://avatar.com",
"Description"
);
await expect(tx).to.revertedWith("AccessDenied");
});

Expand All @@ -58,7 +67,15 @@ describe("Instant Rewards Contract test", () => {
const start = currentBlock.timestamp + 1000;
const end = start + 1000;
const name = "Instant Rewards";
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name);
const tx = instantRewardsFactory.createInstantRewards(
signer.address,
start,
end,
name,
"http://img.com",
"http://avatar.com",
"Description"
);
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated");
});
});
Loading