Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed Apr 26, 2024
1 parent e11eca8 commit 2efb116
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 37 deletions.
27 changes: 8 additions & 19 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ contract Migrator is Governable {
_;

uint256 availableOGN = ogn.balanceOf(address(this));
uint256 totalOGV = ogv.totalSupply() - ogv.balanceOf(address(this));
uint256 maxOGNNeeded = (totalOGV * CONVERSION_RATE) / 1 ether;
uint256 maxOGNNeeded = (ogv.totalSupply() * CONVERSION_RATE) / 1 ether;

if (availableOGN < maxOGNNeeded) {
revert ContractInsolvent(maxOGNNeeded, availableOGN);
Expand All @@ -83,7 +82,7 @@ contract Migrator is Governable {
/**
* @notice Decommissions the contract. Can be called only
* after a year since `start()` was invoked. Burns
* all OGV held in the contract and transfers OGN
* all OGN in the contract by transferring them to
* to address(0xdead).
*/
function decommission() external {
Expand All @@ -94,12 +93,6 @@ contract Migrator is Governable {

emit Decommissioned();

uint256 ogvBalance = ogv.balanceOf(address(this));
if (ogvBalance > 0) {
// Burn all OGV
ogv.burn(ogvBalance);
}

uint256 ognBalance = ogn.balanceOf(address(this));
if (ognBalance > 0) {
// OGN doesn't allow burning of tokens. Has `onlyOwner`
Expand Down Expand Up @@ -137,7 +130,9 @@ contract Migrator is Governable {
}

/**
* @notice Migrates the specified amount of OGV to OGN
* @notice Migrates the specified amount of OGV to OGN.
* Does not check if migration is active since
* that's okay (until we decommission).
* @param ogvAmount Amount of OGV to migrate
* @return ognReceived OGN Received
*/
Expand All @@ -148,6 +143,8 @@ contract Migrator is Governable {
/**
* @notice Migrates OGV stakes to OGN. Can also include unstaked OGN & OGV
* balances from the user's wallet (if specified).
* Does not check if migration is active since that's okay (until
* we decommission the contract).
* @param lockupIds OGV Lockup IDs to be migrated
* @param ogvAmountFromWallet Extra OGV balance from user's wallet to migrate & stake
* @param ognAmountFromWallet Extra OGN balance from user's wallet to stake
Expand All @@ -163,10 +160,6 @@ contract Migrator is Governable {
uint256 newStakeAmount,
uint256 newStakeDuration
) external isSolvent {
if (!isMigrationActive()) {
revert MigrationIsInactive();
}

if (lockupIds.length == 0) {
revert LockupIdsRequired();
}
Expand Down Expand Up @@ -217,15 +210,11 @@ contract Migrator is Governable {
* @return ognReceived OGN Received
*/
function _migrate(uint256 ogvAmount, address receiver) internal returns (uint256 ognReceived) {
if (!isMigrationActive()) {
revert MigrationIsInactive();
}

ognReceived = (ogvAmount * CONVERSION_RATE) / 1 ether;

emit TokenExchanged(ogvAmount, ognReceived);

ogv.transferFrom(msg.sender, address(this), ogvAmount);
ogv.burnFrom(msg.sender, ogvAmount);

if (receiver != address(this)) {
// When migrating stakes, the contract would directly
Expand Down
4 changes: 4 additions & 0 deletions contracts/tests/MockOGV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ contract MockOGV is ERC20 {
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}

function burnFrom(address owner, uint256 amount) external {
_burn(owner, amount);
}
}
30 changes: 12 additions & 18 deletions tests/staking/Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ contract MigratorTest is Test {

function testBalanceMigration() public {
uint256 maxOgnAmount = ogn.balanceOf(address(migrator));
uint256 ogvSupply = ogv.totalSupply();

vm.startPrank(alice);
migrator.migrate(100 ether);
vm.stopPrank();

assertEq(ogv.balanceOf(alice), 10000000 ether - 100 ether, "More OGV sent");
assertEq(ogv.balanceOf(alice), 10000000 ether - 100 ether, "More OGV burnt");
assertEq(ogv.totalSupply(), ogvSupply - 100 ether, "OGV supply mismatch");

assertEq(ogn.balanceOf(alice), 9.137 ether, "Less OGN received");

assertEq(ogv.balanceOf(address(migrator)), 100 ether, "Less OGV received");

assertEq(ogn.balanceOf(address(migrator)), maxOgnAmount - 9.137 ether, "More OGN sent");
}

Expand All @@ -110,10 +109,7 @@ contract MigratorTest is Test {

migrator.decommission();

assertEq(ogv.balanceOf(address(migrator)), 0 ether, "OGV leftover");

assertEq(ogn.balanceOf(address(migrator)), 0 ether, "OGN leftover");

assertEq(ogn.balanceOf(address(0xdead)), maxOgnAmount - 0.09137 ether, "OGN not sent to burn address");
}

Expand Down Expand Up @@ -154,22 +150,20 @@ contract MigratorTest is Test {
vm.stopPrank();
}

function testRevertMigrateAfterTimelimit() public {
function testMigrateAfterTimelimit() public {
// Should allow migration even after timelimit
// but before decommission
vm.startPrank(alice);
ogvStaking.mockStake(10000 ether, 365 days);

vm.warp(migrator.endTime() + 100);

assertEq(migrator.isMigrationActive(), false, "Migration state not changed");

vm.startPrank(alice);

vm.expectRevert(bytes4(keccak256("MigrationIsInactive()")));
migrator.migrate(100 ether);

vm.expectRevert(bytes4(keccak256("MigrationIsInactive()")));
migrator.migrate(1 ether);

vm.expectRevert(bytes4(keccak256("MigrationIsInactive()")));
migrator.migrate(new uint256[](1), 0, 0, false, 1 ether, 0);

uint256[] memory ids = new uint256[](1);
ids[0] = 0;
migrator.migrate(ids, 0, 0, false, 0, 0);
vm.stopPrank();
}

Expand Down

0 comments on commit 2efb116

Please sign in to comment.