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

Add MigrationZapper #432

Merged
merged 6 commits into from
May 30, 2024
Merged

Add MigrationZapper #432

merged 6 commits into from
May 30, 2024

Conversation

shahthepro
Copy link
Collaborator

@shahthepro shahthepro commented May 28, 2024

Right now, it's impossible to convert OGV to OGN and stake it in a single call if you don't have any OGV lockups with our Migrator contract.

The new MigrationZapper will allow users to do that. It internally calls Migrator.migrate and then stakes it on xOGN contract.

The simple migrate(uint256) should:

  • Transfer in OGV from user's wallet
  • Migrate it to OGN
  • And transfer OGN back to the user

The other migrate(uint256,uint256,uint256) should:

  • Transfer in OGV from user's wallet
  • Migrate it to OGN
  • Stake it on behalf of the user for specified duration
  • Transfer back any leftover OGN to user

If you made a contract change, make sure to complete the checklist below before merging it in master.

Contract change checklist:

  • Code reviewed by 2 reviewers.
  • Copy & paste code review security checklist below this checklist.
  • Unit tests pass
  • Slither tests pass with no warning
  • Echidna tests pass if PR includes changes to OUSD contract (not automated, run manually on local)


// Stake on behalf of user
ognStaking.stake(
newStakeAmount,
Copy link

@pandadefi pandadefi May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The ognReceived might be greater than the newStakeAmount, the difference should be sent back to msg.sender.
  • If some ogn are "staying" on the contract, anyone could stake it on his behalf using a really small amount of ogv to migrate and a larger stake amount to swipe the balance of the contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Good catch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed as well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.

IMigrator public immutable migrator;
IStaking public immutable ognStaking;

constructor(address _ogv, address _ogn, address _migrator, address _ognStaking) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are willing to add ownership to this contract, I suggest you add a function to recover funds sent by mistake with an onlyOwner modifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@shahthepro shahthepro requested a review from pandadefi May 28, 2024 14:47

// Migrate
uint256 ognReceived = migrator.migrate(ogvAmount);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add a:

require(ognReceived >= newStakeAmount, "Not enough OGN received");

Afaik ogn/ogv conversion rates should be locked, and such check should only be triggered by faulty math. Though it is still nice to have an understandable error message

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we were just running into this error (DApp was sending a higher amount due to a rounding issue)

Copy link
Member

@sparrowDom sparrowDom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

governor = _governor;
}

function initialize() external {
Copy link
Contributor

@DanielVF DanielVF May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, initialize can't do any damage, so it's okay if it's called multiple times, but this should have an initializer modifier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, if no proxy, this initialize code could move into constructor.

revert NotGovernor();
}

IMintableERC20(token).transfer(governor, amount);
Copy link
Contributor

@DanielVF DanielVF May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nobody should send us USDC, but a generic token transfer method should usually use safeMath, since this call will fail on USDC, anything else that does not return a boolean on transfer.

@shahthepro shahthepro merged commit 9a44bd7 into master May 30, 2024
@shahthepro shahthepro deleted the shah/migrator-and-stake-balance branch May 30, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants