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

Support migrating from Maker CDPs #44

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

kevincheng96
Copy link
Contributor

@kevincheng96 kevincheng96 commented Oct 27, 2022

This PR adds support to Migrator 2.0 for migrating from Maker CDPs. I've also updated the spec to be up-to-date with the implementation.

SPEC.md Outdated Show resolved Hide resolved
@kevincheng96 kevincheng96 temporarily deployed to Production October 27, 2022 23:10 Inactive
@kevincheng96 kevincheng96 temporarily deployed to Production October 28, 2022 18:38 Inactive
@kevincheng96
Copy link
Contributor Author

kevincheng96 commented Oct 28, 2022

Pushed up two more changes:

  1. Check that the user actually has permission to modify the vault before proceeding. Previously, a user was able to migrate funds from any vault that the Migrator has been given permission for. (I also made sure this isn't an issue for Compound II/Aave v2)
  2. Only supply collateral to Comet if the amount is non-zero. This allows the Migrator to still migrate borrows from non-supported collateral CDPs (e.g. MANA), as long as the collateral to migrate is set to 0.

@kevincheng96 kevincheng96 temporarily deployed to Production October 28, 2022 19:08 Inactive
- **REVERT** `UnauthorizedCDP(cdpId)`
- **WHEN** `borrowAmount == type(uint256).max`:
- **BIND READ** `repayAmount = getVaultDebt(vat, ilk, urn)`
- **BIND READ** `(, dart) = ​​-vat.urns(ilk, urn)`
Copy link

Choose a reason for hiding this comment

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

Is vat.urns guaranteed to be <= 0?

withdrawAmount = position.collateralAmount;

// **BIND** `withdrawAmount18 = collateralAmount * (10 ** (18 - gemJoin.dec()))`
withdrawAmount18 = position.collateralAmount * (10 ** (18 - position.gemJoin.dec()));
Copy link

Choose a reason for hiding this comment

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

This is kinda tricky, some more commentary on why these decimal conversions are correct might be useful for posterity

dart = signed256(amount * RAY / rate);
// Checks the calculated dart is not higher than urn.art (total debt), otherwise uses its value
dart = uint256(dart) <= art ? -dart : -signed256(art);
}
Copy link

Choose a reason for hiding this comment

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

On the verge of wondering if it would make sense to separate 'modules' into contracts e.g. w/ the Maker structs / helpers defined separately?

CometMigratorV2.CDPPosition[] memory cdpPosition = new CometMigratorV2.CDPPosition[](1);
cdpPosition[0] = CometMigratorV2.CDPPosition({
cdpId: cdpIds[0],
collateralAmount: 100e18, // XXX withdrawing all without max doesn't work due to dust
Copy link

Choose a reason for hiding this comment

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

So can't exit the CDP with dust remaining?

@@ -7,6 +7,9 @@ import "forge-std/Test.sol";
import "./MainnetConstantsV2.t.sol";

contract Positor is Test, MainnetConstants {
// Units used in Maker contracts
uint256 internal constant RAY = 10**27;

// XXX change name to `PositCompoundV2`?
Copy link

Choose a reason for hiding this comment

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

I guess not necessary?

Copy link

@jflatow jflatow left a comment

Choose a reason for hiding this comment

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

LGTM, but a lot of complexity added here that I can't say I fully understand so I wouldn't mind taking a deeper dive if that's useful

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.

2 participants