Skip to content

Commit

Permalink
Merge pull request #7 from worldcoin/reservations
Browse files Browse the repository at this point in the history
Reservations
  • Loading branch information
karankurbur authored Jan 2, 2024
2 parents d228cf5 + d1252f8 commit 58d5962
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 232 deletions.
6 changes: 3 additions & 3 deletions script/LaunchGrant.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ pragma solidity ^0.8.19;

import {Script} from "forge-std/Script.sol";

import {LaunchGrant} from "src/LaunchGrant.sol";
import {LaunchGrantLegacy} from "src/LaunchGrantLegacy.sol";

/// @title Deployment script for LaunchGrant
/// @author Worldcoin
contract DeployLaunchGrant is Script {

LaunchGrant grant;
LaunchGrantLegacy grant;

///////////////////////////////////////////////////////////////////
/// CONFIG ///
Expand All @@ -21,7 +21,7 @@ contract DeployLaunchGrant is Script {

function run() external {
vm.startBroadcast(privateKey);
new LaunchGrant();
new LaunchGrantLegacy();
vm.stopBroadcast();
}
}
27 changes: 14 additions & 13 deletions script/RecurringGrantDrop.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {Script} from "forge-std/Script.sol";
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {IWorldIDGroups} from "world-id-contracts/interfaces/IWorldIDGroups.sol";
import {RecurringGrantDrop} from "src/RecurringGrantDrop.sol";
import {MonthlyGrant} from "src/MonthlyGrant.sol";
import {HourlyGrant} from "src/HourlyGrant.sol";
import {WeeklyGrant} from "src/WeeklyGrant.sol";
import {LaunchGrant} from "src/LaunchGrant.sol";
import {RecurringGrantDropLegacy} from "src/RecurringGrantDropLegacy.sol";
import {StagingGrant} from "src/StagingGrant.sol";
import {LaunchGrantLegacy} from "src/LaunchGrantLegacy.sol";
import {WLDGrant} from "src/WLDGrant.sol";
import {IGrant} from "src/IGrant.sol";

/// @title Deployment script for RecurringGrantDrop
Expand All @@ -20,6 +20,10 @@ contract DeployRecurringGrantDrop is Script {

RecurringGrantDrop public airdrop;
IGrant grant;

RecurringGrantDropLegacy public airdropLegacy;
IGrant grantLegacy;

///////////////////////////////////////////////////////////////////
/// CONFIG ///
///////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -50,18 +54,15 @@ contract DeployRecurringGrantDrop is Script {
function run() external {
vm.startBroadcast(privateKey);

if (staging) grant = new HourlyGrant(startOffset, amount);
else grant = new LaunchGrant();
if (staging) grant = new StagingGrant(startOffset, amount);
else grant = new WLDGrant();

airdrop = new RecurringGrantDrop(worldIdRouter, groupId, token, holder, grant);

// Allow relayer addresses
airdrop.addAllowedCaller(address(0x65BF36D6499A504100EB504F0719271F5C4174ec));
airdrop.addAllowedCaller(address(0xd8F7d2d62514895475aFe0C7d75F31390Dd40DE4));
airdrop.addAllowedCaller(address(0xaBE494EaA4ED80de8583C49183E9cbdaDbc3b954));
airdrop.addAllowedCaller(address(0x4399fa85585F90DA110d5BA150fF96C763bc0Aba));
airdrop.addAllowedCaller(address(0xb54A5205eE454f48dDFc23CA26a3836Ba3daCC07));
airdrop.addAllowedCaller(address(0xD2d9438FBcAC1352FEeaf5130B1D725e07CB3b97));
if (!staging) {
grantLegacy = new LaunchGrantLegacy();
airdropLegacy = new RecurringGrantDropLegacy(worldIdRouter, groupId, token, holder, grantLegacy);
}

vm.stopBroadcast();
}
Expand Down
8 changes: 8 additions & 0 deletions src/IGrant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ interface IGrant {
/// @notice Checks whether a grant is valid.
/// @param grantId The grant id to check.
function checkValidity(uint256 grantId) external view;

/// @notice Calculates the grant id for a given timestamp.
/// @param timestamp The timestamp to calculate the grant id for.
function calculateId(uint256 timestamp) external view returns (uint256);

/// @notice Checks whether a reservation is valid.
/// @param timestamp The timestamp to check the reservation for.
function checkReservationValidity(uint256 timestamp) external view;
}
27 changes: 0 additions & 27 deletions src/LaunchGrant.sol

This file was deleted.

48 changes: 48 additions & 0 deletions src/LaunchGrantLegacy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IGrant } from './IGrant.sol';

contract LaunchGrantLegacy is IGrant {
uint256 internal immutable launchDayTimestampInSeconds = 1690167600; // Monday, 24 July 2023 03:00:00

function calculateId(uint256 timestamp) external pure returns (uint256) {
if (timestamp < launchDayTimestampInSeconds) revert InvalidGrant();

uint weeksSinceLaunch = (timestamp - launchDayTimestampInSeconds) / 1 weeks;
// Monday, 24 July 2023 07:00:00 until Monday, 07 August 2023 06:59:59 (2 weeks)
if (weeksSinceLaunch < 2) return 13;
// Monday, 07 August 2023 03:00:00 until Monday, 14 August 2023 02:59:59 (1 week)
if (weeksSinceLaunch < 3) return 14;
return 15 + (weeksSinceLaunch - 3) / 2;
}

function getCurrentId() external view override returns (uint256) {
return this.calculateId(block.timestamp);
}

function getAmount(uint256 grantId) external pure override returns (uint256) {
if (grantId == 13) return 25 * 10**18;
if (grantId == 14) return 10 * 10**18;
return 3 * 10**18;
}

function checkValidity(uint256 grantId) external view override{
if (this.getCurrentId() != grantId) revert InvalidGrant();

if (grantId >= 21) revert InvalidGrant();
}

function checkReservationValidity(uint256 timestamp) external view override {
uint256 grantId = this.calculateId(timestamp);

// No future grants can be claimed.
if (grantId >= this.getCurrentId()) revert InvalidGrant();

// Only until 20 can be redeemed through this contract.
if (grantId >= 21) revert InvalidGrant();

// Reservations are only valid for 12 months.
if (block.timestamp > timestamp + 52 weeks) revert InvalidGrant();
}
}
62 changes: 0 additions & 62 deletions src/MonthlyGrant.sol

This file was deleted.

Loading

0 comments on commit 58d5962

Please sign in to comment.