Skip to content

Commit

Permalink
Merge pull request #79 from stakewise/feature/upgrades
Browse files Browse the repository at this point in the history
Release Token, Merkle Drop
  • Loading branch information
tsudmi authored Apr 27, 2021
2 parents 56e5d0f + 5fe1d77 commit e3bc0e2
Show file tree
Hide file tree
Showing 27 changed files with 1,845 additions and 262 deletions.
507 changes: 507 additions & 0 deletions .openzeppelin/goerli.json

Large diffs are not rendered by default.

507 changes: 507 additions & 0 deletions .openzeppelin/mainnet.json

Large diffs are not rendered by default.

507 changes: 507 additions & 0 deletions .openzeppelin/unknown-31337.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions abi/MerkleDrop.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
},
{
"internalType": "address",
"name": "_token",
Expand Down
21 changes: 17 additions & 4 deletions abi/VestingEscrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@
"type": "function"
},
{
"inputs": [
"inputs": [],
"name": "beneficiary",
"outputs": [
{
"internalType": "address",
"name": "beneficiary",
"name": "",
"type": "address"
},
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "amount",
Expand Down Expand Up @@ -380,6 +388,11 @@
"name": "_recipient",
"type": "address"
},
{
"internalType": "address",
"name": "_beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "_totalAmount",
Expand Down Expand Up @@ -556,7 +569,7 @@
"inputs": [
{
"internalType": "address",
"name": "beneficiary",
"name": "_beneficiary",
"type": "address"
}
],
Expand Down
42 changes: 24 additions & 18 deletions abi/VestingEscrowFactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
"name": "recipient",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
Expand Down Expand Up @@ -238,6 +244,11 @@
"name": "recipient",
"type": "address"
},
{
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
Expand Down Expand Up @@ -387,24 +398,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_admin",
"type": "address"
},
{
"internalType": "address",
"name": "_escrowImplementation",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -531,5 +524,18 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_escrowImplementation",
"type": "address"
}
],
"name": "upgrade",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
Binary file added audits/14-01-2021-RuntimeVerification.pdf
Binary file not shown.
Binary file added audits/18-04-2021-Certik.pdf
Binary file not shown.
16 changes: 11 additions & 5 deletions contracts/interfaces/IVestingEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface IVestingEscrow {
* @param _admin - address of the contract admin.
* @param _token - address of the token.
* @param _recipient - address of the recipient of the tokens.
* @param _beneficiary - address of the tokens beneficiary.
* @param _totalAmount - amount of tokens to vest.
* @param _startTime - start timestamp of the vesting in seconds.
* @param _endTime - end timestamp of the vesting in seconds.
Expand All @@ -38,6 +39,7 @@ interface IVestingEscrow {
address _admin,
address _token,
address _recipient,
address _beneficiary,
uint256 _totalAmount,
uint256 _startTime,
uint256 _endTime,
Expand All @@ -64,6 +66,11 @@ interface IVestingEscrow {
*/
function recipient() external view returns (address);

/**
* @dev Function for fetching the beneficiary address.
*/
function beneficiary() external view returns (address);

/**
* @dev Function for fetching the total vested amount.
*/
Expand Down Expand Up @@ -91,16 +98,15 @@ interface IVestingEscrow {

/**
* @dev Function for stopping the vesting contract.
* Can be called only by admin. The unvested tokens will be transferred to the beneficiary address.
* @param beneficiary - address of the unvested tokens recipient.
* Can be called only by admin. The unvested tokens will be transferred to the `_beneficiary` address.
* @param _beneficiary - address of the unvested tokens recipient.
*/
function stop(address beneficiary) external;
function stop(address _beneficiary) external;

/**
* @dev Function for claiming the vested tokens.
* Can be called only by the tokens recipient. The amount claimed must be vested by the time of calling.
* @param beneficiary - address of the tokens recipient.
* @param amount - amount of tokens to claim.
*/
function claim(address beneficiary, uint256 amount) external;
function claim(uint256 amount) external;
}
9 changes: 6 additions & 3 deletions contracts/interfaces/IVestingEscrowFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IVestingEscrowFactory {
* @param admin - address of the contract admin.
* @param token - address of the token.
* @param recipient - address of the recipient of the tokens.
* @param beneficiary - address of the tokens beneficiary.
* @param escrow - address of the escrow contract.
* @param totalAmount - amount of tokens to vest.
* @param startTime - start timestamp of the vesting in seconds.
Expand All @@ -21,6 +22,7 @@ interface IVestingEscrowFactory {
address indexed admin,
address indexed token,
address indexed recipient,
address beneficiary,
address escrow,
uint256 totalAmount,
uint256 startTime,
Expand All @@ -29,11 +31,10 @@ interface IVestingEscrowFactory {
);

/**
* @dev Constructor for initializing the VestingEscrowFactory contract.
* @param _admin - address of the contract admin.
* @dev Function for upgrading the VestingEscrowFactory contract.
* @param _escrowImplementation - address of the VestingEscrow implementation contract.
*/
function initialize(address _admin, address _escrowImplementation) external;
function upgrade(address _escrowImplementation) external;

/**
* @dev Function for fetching escrow implementation contract.
Expand All @@ -50,6 +51,7 @@ interface IVestingEscrowFactory {
* @dev Function for deploying new escrow contract.
* @param token - address of the token contract.
* @param recipient - address of the recipient of the tokens.
* @param beneficiary - address where the tokens will be sent.
* @param amount - amount of tokens to vest.
* @param vestingStart - start timestamp of the vesting in seconds.
* @param vestingDuration - vesting duration in seconds.
Expand All @@ -58,6 +60,7 @@ interface IVestingEscrowFactory {
function deployEscrow(
address token,
address recipient,
address beneficiary,
uint256 amount,
uint256 vestingStart,
uint256 vestingDuration,
Expand Down
21 changes: 13 additions & 8 deletions contracts/vestings/VestingEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ contract VestingEscrow is IVestingEscrow, OwnablePausableUpgradeable {
// @dev Address of the recipient.
address public override recipient;

// @dev Address of the beneficiary.
address public override beneficiary;

// @dev Total amount vested.
uint256 public override totalAmount;

Expand All @@ -47,6 +50,7 @@ contract VestingEscrow is IVestingEscrow, OwnablePausableUpgradeable {
address _admin,
address _token,
address _recipient,
address _beneficiary,
uint256 _totalAmount,
uint256 _startTime,
uint256 _endTime,
Expand All @@ -57,6 +61,7 @@ contract VestingEscrow is IVestingEscrow, OwnablePausableUpgradeable {
__OwnablePausableUpgradeable_init(_admin);
token = IERC20(_token);
recipient = _recipient;
beneficiary = _beneficiary;
totalAmount = _totalAmount;
startTime = _startTime;
endTime = _endTime;
Expand Down Expand Up @@ -87,8 +92,8 @@ contract VestingEscrow is IVestingEscrow, OwnablePausableUpgradeable {
/**
* @dev See {IVestingEscrow-stop}.
*/
function stop(address beneficiary) external override onlyAdmin {
require(beneficiary != address(0), "PoolEscrow: beneficiary is the zero address");
function stop(address _beneficiary) external override onlyAdmin {
require(_beneficiary != address(0), "PoolEscrow: beneficiary is the zero address");
uint256 _totalAmount = totalAmount;
uint256 pulledAmount = _totalAmount.sub(claimedAmount);
require(pulledAmount > 0, "VestingEscrow: nothing to pull");
Expand All @@ -97,24 +102,24 @@ contract VestingEscrow is IVestingEscrow, OwnablePausableUpgradeable {
endTime = block.timestamp;
claimedAmount = _totalAmount;

emit Stopped(msg.sender, beneficiary, pulledAmount);
token.safeTransfer(beneficiary, pulledAmount);
emit Stopped(msg.sender, _beneficiary, pulledAmount);
token.safeTransfer(_beneficiary, pulledAmount);
}

/**
* @dev See {IVestingEscrow-claim}.
*/
function claim(address beneficiary, uint256 amount) external override whenNotPaused {
require(beneficiary != address(0), "PoolEscrow: beneficiary is the zero address");
function claim(uint256 amount) external override whenNotPaused {
require(msg.sender == recipient, "VestingEscrow: access denied");
require(amount > 0, "VestingEscrow: amount is zero");

uint256 _claimedAmount = claimedAmount;
uint256 claimable = vestedAmount().sub(_claimedAmount);
require(claimable >= amount, "VestingEscrow: invalid amount");

address _beneficiary = beneficiary;
claimedAmount = _claimedAmount.add(amount);
emit Claimed(msg.sender, beneficiary, amount);
token.safeTransfer(beneficiary, amount);
emit Claimed(msg.sender, _beneficiary, amount);
token.safeTransfer(_beneficiary, amount);
}
}
14 changes: 10 additions & 4 deletions contracts/vestings/VestingEscrowFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ contract VestingEscrowFactory is IVestingEscrowFactory, ReentrancyGuardUpgradeab
mapping(address => address[]) private escrows;

/**
* @dev See {IVestingEscrowFactory-initialize}.
*/
function initialize(address _admin, address _escrowImplementation) external override initializer {
__OwnablePausableUpgradeable_init(_admin);
* @dev See {IVestingEscrowFactory-upgrade}.
* The `initialize` must be called before upgrading in previous implementation contract:
* https://github.com/stakewise/contracts/blob/f865adf3b90818e6d8b9d8af01080842fb24aa16/contracts/vestings/VestingEscrowFactory.sol#L35
*/
function upgrade(address _escrowImplementation) external override onlyAdmin whenPaused {
require(_escrowImplementation != escrowImplementation, "VestingEscrowFactory: already upgraded");
escrowImplementation = _escrowImplementation;
}

Expand All @@ -53,6 +55,7 @@ contract VestingEscrowFactory is IVestingEscrowFactory, ReentrancyGuardUpgradeab
function deployEscrow(
address token,
address recipient,
address beneficiary,
uint256 amount,
uint256 vestingStart,
uint256 vestingDuration,
Expand All @@ -62,6 +65,7 @@ contract VestingEscrowFactory is IVestingEscrowFactory, ReentrancyGuardUpgradeab
{
require(cliffLength <= vestingDuration, "VestingEscrowFactory: invalid cliff");
require(recipient != address(0), "PoolEscrow: recipient is the zero address");
require(beneficiary != address(0), "PoolEscrow: beneficiary is the zero address");

IERC20Upgradeable(token).safeTransferFrom(msg.sender, address(this), amount);

Expand All @@ -76,6 +80,7 @@ contract VestingEscrowFactory is IVestingEscrowFactory, ReentrancyGuardUpgradeab
msg.sender,
token,
recipient,
beneficiary,
amount,
vestingStart,
vestingEnd,
Expand All @@ -85,6 +90,7 @@ contract VestingEscrowFactory is IVestingEscrowFactory, ReentrancyGuardUpgradeab
msg.sender,
token,
recipient,
beneficiary,
escrow,
amount,
vestingStart,
Expand Down
12 changes: 0 additions & 12 deletions deployments/collectors.js

This file was deleted.

Loading

0 comments on commit e3bc0e2

Please sign in to comment.