Skip to content

Commit

Permalink
new LaunchGrantLegacy (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-schaaf authored Aug 27, 2024
1 parent caf3793 commit 6da3a45
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
31 changes: 31 additions & 0 deletions script/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ async function deployAirdropReservations(config) {
}
}

async function deployLaunchGrantLegacy(config) {
dotenv.config();

await getPrivateKey(config);

const spinner = ora(`Deploying LaunchGrantLegacy contract...`).start();

try {
const data = execSync(
`forge script script/LaunchGrantLegacy.s.sol:DeployLaunchGrant--fork-url ${config.ethereumRpcUrl} \
--etherscan-api-key ${config.ethereumEtherscanApiKey} --broadcast --verify -vvvv`
);
console.log(data.toString());
spinner.succeed('Deployed LaunchGrantLegacy contract successfully!');
} catch (err) {
console.error(err);
spinner.fail('Deployment of LaunchGrantLegacy has failed.');
}
}

async function deployWLDGrantPreGrant4(config) {
dotenv.config();

Expand Down Expand Up @@ -387,6 +407,17 @@ async function addAllowedNullifierHashBlocker(config) {
async function main() {
const program = new Command();

program
.name('deploy-launch-grant-legacy')
.command('deploy-launch-grant-legacy')
.description('Deploys the LaunchGrantLegacy contract')
.action(async () => {
const options = program.opts();
let config = await loadConfiguration(options.config);
await deployLaunchGrantLegacy(config);
await saveConfiguration(config);
});

program
.name('deploy-airdrop')
.command('deploy-airdrop')
Expand Down
3 changes: 0 additions & 3 deletions src/LaunchGrantLegacy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ contract LaunchGrantLegacy is IGrant {

// 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();
}
}
48 changes: 48 additions & 0 deletions src/LaunchGrantLegacyPreGrant4.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 "./IGrantPreGrant4.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();

uint256 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();
}
}

0 comments on commit 6da3a45

Please sign in to comment.