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(supplementary-contracts): make unlocking deployments and vesting scriptable #16918

Merged
merged 7 commits into from
Apr 30, 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
1 change: 1 addition & 0 deletions packages/supplementary-contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ block_gas_limit = 80_000_000
fs_permissions = [
{ access = "read", path = "./out" },
{ access = "read-write", path = "./deployments" },
{ access = "read", path = "./script" },
{ access = "read", path = "./test" },
{ access = "read", path = "./genesis" },
]
Expand Down
36 changes: 0 additions & 36 deletions packages/supplementary-contracts/script/DeployTokenUnlocking.s.sol

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "Alice",
"recipient": "0xa48dEBc18D5e63F1FB94DD513f643e412684f8a4",
"proxy": "0x33A270541f383A4A48dB6C5f1f00A161b8F79e2a",
"vestAmount": 35000
},
{
"name": "Bob",
"recipient": "0xa48dEBc18D5e63F1FB94DD513f643e412684f8a4",
"proxy": "0x33A270541f383A4A48dB6C5f1f00A161b8F79e2a",
"vestAmount": 25000
},
{
"name": "Carol",
"recipient": "0xa48dEBc18D5e63F1FB94DD513f643e412684f8a4",
"proxy": "0x33A270541f383A4A48dB6C5f1f00A161b8F79e2a",
"vestAmount": 15000
}
]
56 changes: 56 additions & 0 deletions packages/supplementary-contracts/script/tokenVesting/Vest.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "forge-std/src/Script.sol";
import "forge-std/src/console2.sol";

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import "../../contracts/tokenUnlocking/TokenUnlocking.sol";

contract VestTokenUnlocking is Script {
using stdJson for string;

struct VestingItem {
bytes32 name; // Conversion from json "string" to bytes32 will take place in foundry,
// cannot use string here, as json parser cannot interpret string from json, everything
// is bytes-chunks. It is more of informational to script executor anyways.
address recipient;
address proxy;
uint256 vestAmount;
}

ERC20 private tko = ERC20(vm.envAddress("TAIKO_TOKEN"));

function run() external {
vm.startBroadcast();

string memory path = "/script/tokenVesting/Vest.data.json";
VestingItem[] memory items = abi.decode(
vm.parseJson(vm.readFile(string.concat(vm.projectRoot(), path))), (VestingItem[])
);

for (uint256 i; i < items.length; i++) {
address proxy = items[i].proxy;
console2.logBytes32(items[i].name);
console2.log("Grantee unlocking contract address:", proxy);
console2.log("Vest amount (TKO):", items[i].vestAmount);

require(TokenUnlocking(proxy).owner() == msg.sender, "msg.sender not owner");
require(
TokenUnlocking(proxy).recipient() == items[i].recipient, "inconsistent recipient"
);

uint128 vestAmount = uint128(items[i].vestAmount * 1e18);
require(tko.balanceOf(msg.sender) >= vestAmount, "insufficient TKO balance");

tko.approve(proxy, vestAmount);
TokenUnlocking(proxy).vest(vestAmount);

console2.log("Vested!\n");
}

vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"0xa48dEBc18D5e63F1FB94DD513f643e412684f8a4",
"0x33A270541f383A4A48dB6C5f1f00A161b8F79e2a",
"0x5486893fE4b289e3395E382fDdF203238cBa857e"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "forge-std/src/Script.sol";
import "forge-std/src/console2.sol";

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

import "../../contracts/tokenUnlocking/TokenUnlocking.sol";

contract DeployTokenUnlocking is Script {
using stdJson for string;

uint256 public PRIVATE_KEY = vm.envUint("PRIVATE_KEY"); // deployer
address public OWNER = vm.envAddress("OWNER");
address public TAIKO_TOKEN = vm.envAddress("TAIKO_TOKEN");
uint256 public TGE = vm.envUint("TGE_TIMESTAMP");
address public IMPL = vm.envAddress("TOKEN_VESTING_IMPL");

function setUp() public { }

function run() external {
address impl = IMPL == address(0) ? address(new TokenUnlocking()) : IMPL;

string memory path = "/script/tokenUnlocking/Deploy.data.json";
address[] memory recipients = abi.decode(
vm.parseJson(vm.readFile(string.concat(vm.projectRoot(), path))), (address[])
);

for (uint256 i; i < recipients.length; i++) {
console2.log("Grantee:", recipients[i]);

vm.startBroadcast(PRIVATE_KEY);
deployProxy({
impl: impl,
data: abi.encodeCall(
TokenUnlocking.init, (OWNER, TAIKO_TOKEN, recipients[i], uint64(TGE))
)
});
vm.stopBroadcast();
console2.log("Deployed!\n");
}
}

function deployProxy(address impl, bytes memory data) public returns (address proxy) {
proxy = address(new ERC1967Proxy(impl, data));
console2.log(" proxy :", proxy);
console2.log(" impl :", impl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "forge-std/src/console2.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "../contracts/TokenUnlocking.sol";
import "../../contracts/tokenUnlocking/TokenUnlocking.sol";

contract MyERC20 is ERC20, ERC20Votes {
constructor(address owner) ERC20("Taiko Token", "TKO") ERC20Permit("Taiko Token") {
Expand Down