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 ERC20-compatible Escape Hatch to Gem Join Contracts #138

Closed
hexonaut opened this issue Sep 21, 2020 · 1 comment
Closed

Add ERC20-compatible Escape Hatch to Gem Join Contracts #138

hexonaut opened this issue Sep 21, 2020 · 1 comment

Comments

@hexonaut
Copy link
Contributor

hexonaut commented Sep 21, 2020

It's a common pattern to include an ERC20 token extraction mechanism in rapidly developed contracts in case of accidentally trapped funds. I think it could be useful to upgrade all the gem join contracts to be compliant with part of the ERC20 standard - specifically transfer, transferFrom and balanceOf. This would basically provide an ERC20-compliant escape hatch for accidentally stuck collateral to be extracted from Maker.

The functions would look something like this (pseudocode):

function balanceOf (account) {
	// Return the ink that can be freed from vat.frob (after repaying with the available vat.dai) and any vat.gem available
}

function transfer (address recipient, uint amount) {
	if (vat.gem[ilk][msg.sender] < amount) {
		// Pull the ink out of the cdp and repay as much dai as available
		vat.frob(ilk, msg.sender, msg.sender, msg.sender, -int(sub(amount, vat.gem[ilk][msg.sender])), -int(vat.dai[msg.sender]));
	}

	exit(recipient, amount);
}

function transferFrom (address sender, address recipient, uint amount) {
	require(sender == msg.sender)

	transfer(recipient, amount);
}

This would allow anyone to completely unwind a CDP with only the ERC20 transfer semantics as any account is able to repay debt. So for example to unwind my locked CDP, I can do: Flash Loan (Dai), Repay all CDP Debt, gemJoin.transfer(myAccount, gemJoin.getBalance()), Trade Gem for Dai, Repay Flash Dai Loan.

The only downside I can see to this is a slight increase in code complexity, but we get the added benefit of lower liquidations from trapped funds.

@hexonaut
Copy link
Contributor Author

hexonaut commented Feb 3, 2021

Changed my view on this - the code is unnecessary bloat. Closing.

@hexonaut hexonaut closed this as completed Feb 3, 2021
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

No branches or pull requests

1 participant