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

Reclaim OGN After #412

Merged
merged 24 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f205b0
Add OGNRewardsSource contract
shahthepro Apr 17, 2024
8e45acc
Make collectRewards only callable by RewardsTarget
shahthepro Apr 17, 2024
ef72063
Draft xOGN staking contract
DanielVF Apr 17, 2024
1126cf2
Correct maxStakeDuration
DanielVF Apr 18, 2024
cd1bfda
Add penalty event
DanielVF Apr 18, 2024
ff30762
Change names
shahthepro Apr 21, 2024
7997625
Merge branch 'DanielVF/xogn2' into shah/ogn-rewards-source
shahthepro Apr 21, 2024
3f51c2d
Fix lockup ID
shahthepro Apr 21, 2024
c02d6b5
Revert change and cast properly
shahthepro Apr 21, 2024
f3db15a
Merge branch 'DanielVF/xogn2' into shah/ogn-rewards-source
shahthepro Apr 21, 2024
7e0daae
Gas opts
shahthepro Apr 22, 2024
db52be3
Remove casting
shahthepro Apr 24, 2024
820fccf
Add `getLockupsCount` method (#411)
shahthepro Apr 24, 2024
3784333
Allow non-duration change amount increase staking extends
DanielVF Apr 24, 2024
1864b68
Add tests, add move lockupid code
DanielVF Apr 25, 2024
50a0021
Merge branch 'DanielVF/xogn2' into shah/ogn-rewards-source
shahthepro Apr 26, 2024
3c3b799
Add Migrator (#410)
shahthepro Apr 26, 2024
230755a
Return excess OGN rather than burn
DanielVF Apr 26, 2024
d0fd40f
Simplify calculation
DanielVF Apr 26, 2024
51035a9
Return 0 if uninitialized (#415)
shahthepro May 8, 2024
2a51241
Check available balance in `previewRewards` (#413)
shahthepro May 8, 2024
c747eea
Fix: Remove unused errors (#416)
DanielVF May 14, 2024
1f69918
Merge branch 'shah/ogn-rewards-source' into DanielVF/reclaimAfter
shahthepro May 16, 2024
ae22e7c
Merge branch 'master' into DanielVF/reclaimAfter
DanielVF May 16, 2024
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
40 changes: 7 additions & 33 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ contract Migrator is Governable {
event LockupsMigrated(address indexed user, uint256[] ogvLockupIds, uint256 newStakeAmount, uint256 newDuration);

error MigrationAlreadyStarted();
error MigrationIsInactive();
error MigrationNotComplete();
error ContractInsolvent(uint256 expectedOGN, uint256 availableOGN);
error LockupIdsRequired();
error InvalidStakeAmount();
Expand Down Expand Up @@ -79,45 +77,21 @@ contract Migrator is Governable {
endTime = block.timestamp + 365 days;
}

/**
* @notice Decommissions the contract. Can be called only
* after a year since `start()` was invoked. Burns
* all OGN in the contract by transferring them to
* to address(0xdead).
*/
function decommission() external {
// Only after a year of staking
if (endTime == 0 || isMigrationActive()) {
revert MigrationNotComplete();
}

emit Decommissioned();

uint256 ognBalance = ogn.balanceOf(address(this));
if (ognBalance > 0) {
// OGN doesn't allow burning of tokens. Has `onlyOwner`
// modifier on `burn` and `burnFrom` methods. Also,
// `transfer` has a address(0) check. So, this transfers
// everything to address(0xdead). The `owner` multisig of
// OGN token can call `burnFrom(address(0xdead))` later.

ogn.transfer(address(0xdead), ognBalance);
}
}

/**
* @notice Computes the amount of OGN needed for migration
* and if the contract has more OGN than that, it
* transfers it back to the treasury.
* transfers it back to the treasury. If migration complete, transfers all.
* @param treasury Address that receives excess OGN
*/
function transferExcessTokens(address treasury) external onlyGovernor isSolvent {
function transferExcessTokens(address treasury) external onlyGovernor {
uint256 availableOGN = ogn.balanceOf(address(this));
uint256 totalOGV = ogv.totalSupply() - ogv.balanceOf(address(this));
uint256 maxOGNNeeded = (totalOGV * CONVERSION_RATE) / 1 ether;

if (availableOGN > maxOGNNeeded) {
if (endTime == 0 || isMigrationActive()) {
uint256 maxOGNNeeded = (ogv.totalSupply() * CONVERSION_RATE) / 1 ether;
ogn.transfer(treasury, availableOGN - maxOGNNeeded);
} else {
emit Decommissioned();
ogn.transfer(treasury, availableOGN);
}
}

Expand Down
18 changes: 2 additions & 16 deletions tests/staking/Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ contract MigratorTest is Test {
vm.stopPrank();

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

migrator.decommission();
vm.prank(governor);
migrator.transferExcessTokens(address(0xdead));

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 @@ -167,20 +167,6 @@ contract MigratorTest is Test {
vm.stopPrank();
}

function testRevertDecommissionBeforeEnd() public {
vm.warp(migrator.endTime() - 1000);

vm.expectRevert(bytes4(keccak256("MigrationNotComplete()")));
migrator.decommission();
}

function testRevertDecommissionBeforeStart() public {
Migrator newMigrator = new Migrator(address(ogv), address(ogn), address(1), address(1));

vm.expectRevert(bytes4(keccak256("MigrationNotComplete()")));
newMigrator.decommission();
}

function testMigrateStakes() public {
vm.startPrank(alice);
ogvStaking.mockStake(10000 ether, 365 days);
Expand Down
Loading