-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1 smart contract per activity (#195)
* feat: 1 smart contract per activity * add test * remove unused code * add validations * deploy to testnet
- Loading branch information
1 parent
41c98cd
commit 0f7b077
Showing
7 changed files
with
540 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/zevm-app-contracts/contracts/instant-rewards/InstantRewardsFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/access/Ownable2Step.sol"; | ||
import "./InstantRewardsV2.sol"; | ||
|
||
contract InstantRewardsFactory is Ownable2Step { | ||
bool public allowPublicCreation = false; | ||
|
||
error AccessDenied(); | ||
error InvalidSignerAddress(); | ||
error EmptyName(); | ||
error StartTimeInPast(); | ||
error EndTimeBeforeStart(); | ||
|
||
event InstantRewardsCreated(address indexed instantRewards, address indexed owner); | ||
|
||
constructor(address owner) Ownable() { | ||
transferOwnership(owner); | ||
} | ||
|
||
function setAllowPublicCreation(bool allowPublicCreation_) external onlyOwner { | ||
allowPublicCreation = allowPublicCreation_; | ||
} | ||
|
||
function createInstantRewards( | ||
address signerAddress, | ||
uint256 start, | ||
uint256 end, | ||
string memory name | ||
) external returns (address) { | ||
if (signerAddress == address(0)) revert InvalidSignerAddress(); | ||
if (bytes(name).length == 0) revert EmptyName(); | ||
if (start < block.timestamp) revert StartTimeInPast(); | ||
if (end <= start) revert EndTimeBeforeStart(); | ||
|
||
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()); | ||
return address(instantRewards); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/zevm-app-contracts/contracts/instant-rewards/InstantRewardsV2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "./InstantRewards.sol"; | ||
|
||
contract InstantRewardsV2 is InstantRewards { | ||
string public name; | ||
|
||
uint256 public start; | ||
uint256 public end; | ||
|
||
event TimeframeUpdated(uint256 start, uint256 end); | ||
|
||
error InvalidTimeframe(); | ||
error InstantRewardNotActive(); | ||
error InstantRewardStillActive(); | ||
|
||
constructor( | ||
address signerAddress_, | ||
address owner, | ||
uint256 start_, | ||
uint256 end_, | ||
string memory name_ | ||
) InstantRewards(signerAddress_, owner) { | ||
if (signerAddress_ == address(0)) revert InvalidAddress(); | ||
if (start_ > end_) revert InvalidTimeframe(); | ||
start = start_; | ||
end = end_; | ||
name = name_; | ||
} | ||
|
||
function isActive() public view returns (bool) { | ||
return block.timestamp >= start && block.timestamp <= end; | ||
} | ||
|
||
function setTimeframe(uint256 start_, uint256 end_) external onlyOwner { | ||
if (start_ > end_) revert InvalidTimeframe(); | ||
if (start_ < block.timestamp || end_ < block.timestamp) revert InvalidTimeframe(); | ||
if (isActive()) revert InstantRewardStillActive(); | ||
start = start_; | ||
end = end_; | ||
emit TimeframeUpdated(start_, end_); | ||
} | ||
|
||
function claim(ClaimData memory claimData) public override { | ||
if (!isActive()) revert InstantRewardNotActive(); | ||
super.claim(claimData); | ||
} | ||
|
||
function withdraw(address wallet, uint256 amount) public override onlyOwner { | ||
if (isActive()) revert InstantRewardStillActive(); | ||
super.withdraw(wallet, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/zevm-app-contracts/scripts/instant-rewards/deploy-v2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { InstantRewardsFactory__factory } from "../../typechain-types"; | ||
import { saveAddress } from "../address.helpers"; | ||
import { verifyContract } from "../explorer.helpers"; | ||
|
||
const networkName = network.name; | ||
|
||
const owner = "0x1d24d94520B94B26351f6573de5ef9731c48531A"; | ||
|
||
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); | ||
|
||
await InstantRewards.deployed(); | ||
|
||
console.log("InstantRewards deployed to:", InstantRewards.address); | ||
|
||
saveAddress("InstantRewards", InstantRewards.address, networkName); | ||
|
||
await verifyContract(InstantRewards.address, [owner]); | ||
}; | ||
|
||
const main = async () => { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
await deployInstantRewards(); | ||
}; | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.