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

chore: latest deployments #83

Merged
merged 1 commit into from
Oct 9, 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
117 changes: 117 additions & 0 deletions contracts/TokenLocker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.24;

import { IERC20, IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";

contract TokenLocker is Ownable2Step {
IERC20 public asset;

uint256 public lockPeriod;
uint256 public participantNumber;
uint256 public totalSupply;
uint256 public constant MAX_LOCK_PERIOD = 60 * 60 * 24 * 180;

string public name;
string public symbol;

mapping(address => uint256) public lockedDeposit;
mapping(address => uint256) public unlockTime;

event LockPeriodUpdated(uint256 lockPeriod);
event Deposit(address depositor, uint256 amount);
event Withdraw(address caller, address receiver, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 value);

error InvalidDepositAmount();
error InsufficientLockPeriod();
error InsufficientDeposit();
error ZeroAddressReceipient();
error InvalidLockPeriod();

modifier onlyValidLockPeriod(uint256 _lockPeriod) {
if (_lockPeriod > MAX_LOCK_PERIOD) {
revert InvalidLockPeriod();
}
_;
}

constructor(
address _owner,
IERC20 _asset,
uint256 _lockPeriod,
string memory _name,
string memory _symbol
) onlyValidLockPeriod(_lockPeriod) {
asset = _asset;
lockPeriod = _lockPeriod;
name = _name;
symbol = _symbol;
_transferOwnership(_owner);
}

function updateLockPeriod(uint256 _lockPeriod) external onlyOwner onlyValidLockPeriod(_lockPeriod) {
lockPeriod = _lockPeriod;

emit LockPeriodUpdated(_lockPeriod);
}

function deposit(uint256 _amount) external {
if (_amount == 0) {
revert InvalidDepositAmount();
}
if (lockedDeposit[msg.sender] == 0) {
unchecked {
++participantNumber;
}
}

SafeERC20.safeTransferFrom(asset, msg.sender, address(this), _amount);

lockedDeposit[msg.sender] += _amount;
unlockTime[msg.sender] = block.timestamp;
totalSupply += _amount;

emit Deposit(msg.sender, _amount);
emit Transfer(address(0), msg.sender, _amount);
}

function withdraw(uint256 _amount, address _receiver) external {
if (_receiver == address(0)) {
revert ZeroAddressReceipient();
}
uint256 userLockedDeposit = lockedDeposit[msg.sender];
if (userLockedDeposit < _amount) {
revert InsufficientDeposit();
}
if (block.timestamp < getUnlockableTimestamp(msg.sender)) {
revert InsufficientLockPeriod();
}
if ((userLockedDeposit - _amount) == 0) {
delete unlockTime[msg.sender];
--participantNumber;
}

lockedDeposit[msg.sender] -= _amount;
totalSupply -= _amount;

SafeERC20.safeTransfer(asset, _receiver, _amount);

emit Withdraw(msg.sender, _receiver, _amount);
emit Transfer(msg.sender, address(0), _amount);
}

function getUnlockableTimestamp(address _locker) public view returns (uint256) {
uint256 unlock = unlockTime[_locker];
return (unlock == 0) ? 0 : unlock + lockPeriod;
}

function decimals() external view returns (uint256) {
return IERC20Metadata(address(asset)).decimals();
}

function balanceOf(address _locker) external view returns (uint256) {
return lockedDeposit[_locker];
}
}
7 changes: 6 additions & 1 deletion contracts/tokenWrappers/RadiantTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

interface IVesting {
function rdntToken() external view returns (address);
function vestTokens(address, uint256, bool) external;

Check failure on line 13 in contracts/tokenWrappers/RadiantTokenWrapper.sol

View workflow job for this annotation

GitHub Actions / lint

Insert ⏎
}

/// @title Radiant MTW
Expand All @@ -24,7 +24,7 @@

// ================================= CONSTANTS =================================

IVesting public constant VESTING = IVesting(0x28E395a54a64284DBA39652921Cd99924f4e3797);
IVesting public constant VESTING = IVesting(0x76ba3eC5f5adBf1C58c91e86502232317EeA72dE);
address internal immutable _UNDERLYING = VESTING.rdntToken();

// ================================= FUNCTIONS =================================
Expand Down Expand Up @@ -60,4 +60,9 @@
VESTING.vestTokens(to, amount, true);
}
}

function overrideNameAndSymbol() public onlyGovernor {
_name = string.concat("Merkl Token Wrapper - ", IERC20Metadata(token()).name());
_symbol = string.concat("mtw", IERC20Metadata(token()).symbol());
}
}
18 changes: 9 additions & 9 deletions deploy/mtw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
console.log(`Deploying Coupon`);
console.log('Starting with the implementation');

await deploy(`${couponName}_Implementation`, {
await deploy(`${couponName}_Implementation_V2`, {
contract: couponName,
from: deployer.address,
args: [],
log: !argv.ci,
});

const implementationAddress = (await ethers.getContract(`${couponName}_Implementation`)).address;
const implementationAddress = (await ethers.getContract(`${couponName}_Implementation_V2`)).address;

console.log('Starting with the implementation');

const distributorInterface = Distributor__factory.createInterface();
// const distributorInterface = Distributor__factory.createInterface();

await deploy(`${couponName}_Proxy`, {
contract: 'ERC1967Proxy',
from: deployer.address,
args: [implementationAddress, distributorInterface.encodeFunctionData('initialize', [core])],
log: !argv.ci,
});
// await deploy(`${couponName}_Proxy`, {
// contract: 'ERC1967Proxy',
// from: deployer.address,
// args: [implementationAddress, distributorInterface.encodeFunctionData('initialize', [core])],
// log: !argv.ci,
// });

console.log(`Successfully deployed the contract ${couponName} at ${implementationAddress}`);
console.log('');
Expand Down
29 changes: 29 additions & 0 deletions deploy/tokenLocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DistributionCreator__factory } from '@angleprotocol/sdk';
import { DeployFunction } from 'hardhat-deploy/types';
import yargs from 'yargs';
import { Distributor__factory } from '../typechain';

const argv = yargs.env('').boolean('ci').parseSync();

const func: DeployFunction = async ({ deployments, ethers, network }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();

console.log(`Deploying TokenLocker`);

await deploy(`TokenLocker2`, {
contract: 'TokenLocker',
from: deployer.address,
args: ['0x2Dd2290EabdB5654609352Cc267C9BAc82d01877', '0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B', 60*5, 'Locked slisBNB', 'LslisBNB'],
log: !argv.ci,
});

const implementationAddress = (await ethers.getContract(`TokenLocker`)).address;


console.log(`Successfully deployed the contract TokenLocker at ${implementationAddress}`);
console.log('');
};

func.tags = ['locker'];
export default func;
Loading
Loading