CToken sweepToken function

Following up on the idea of returning accidental funds sent to cTokens when possible, I wrote a quick code change which enables us to do this. The new function sweepToken(address) is a very simple addition which allows anyone to sweep the entire balance of any ERC20 (except for the underlying) to the admin (timelock).

The new function is as follows for CErc20:

/**
  * @notice A public function to sweep accidental ERC-20 transfers to this contract. Tokens are sent to admin (timelock)
  * @param token The address of the ERC-20 token to sweep
  */
function sweepToken(EIP20Interface token) external {
  require(address(token) != underlying, "CErc20::sweepToken: can not sweep underlying token");
  uint256 balance = token.balanceOf(address(this));
  token.transfer(admin, balance);
}

And as follows for CEther:

/**
  * @notice A public function to sweep accidental ERC-20 transfers to this contract. Tokens are sent to admin (timelock)
  * @param token The address of the ERC-20 token to sweep
  */
function sweepToken(EIP20Interface token) external {
  uint256 balance = token.balanceOf(address(this));
  token.transfer(admin, balance);
}

I wrote scenario tests for the new function and a forking simulation ensuring that the new code performs as expected. Please take a review the pull request and leave feedback.

6 Likes

I’ve seen your Github.
I don’t know the technical details, so please tell me.

What, exactly, is this proposal?
Please include the benefits!

Thanks for asking.

This function will allow for ERC-20 tokens which were accidentally sent to cToken contracts to be recoverable by governance. For example, in this transaction, cUNI was accidentally sent to the cUNI address. Adopting this new code will allow for governance to return these currently bricked funds.

4 Likes

Quick reply, thanks!

I think it’s a great suggestion.

I’ll be rooting for you!

That was my transaction! My good sir, if there is any portion of those coins returned to me I will certainly be sending you your fair share. Words can not describe the appreciation and gratitude that has come over me. There are still good people in this world :'D

1 Like

@arr00 this is a great feature to add to the “base” cToken; it will help return accidentally trapped / incorrectly transferred funds, by routing them to the Timelock contract for redistribution (through governance proposals) to users.

Given that the admin and underlying are defined on each token, these functions should be generally safe and low risk. It would be great for the community to verify (and test-case), but this looks logically correct & simple.

Note: this will not apply to cETH, cBAT, cZRX, cUSDC, and cWBTC, which are not upgradable–but can apply to all newer cTokens, including cDAI, cUSDT, cUNI, and cCOMP.

After deploying a new cToken implementation (and upgrading DAI, USDT, UNI, and COMP) the community should develop some heuristics or policy for how funds are returned to users – governance proposals are time-consuming and onerous, and the distribution process shouldn’t be taken lightly.

3 Likes

I will be glad to tribute my transaction of cDAI that has become trapped in a contract in limbo as a guinea pig for the initial test. If something goes wrong and they become erased or burned and leave them unrecoverable, then so be it, it would be worth the effort put forth by the community.

Correct me if I’m wrong, seems idea would be for the missent tokens to be swept to the timelock and decided on what to do with it via a governance proposal (returning to respective owners would be the most altruist option).

This is actually very much needed!

1 Like

Can you please send the tx id?

Yes, that is exactly the thought.

0xeafecc481b37c1f1688842f41ce8fb1264

d12a0da292b6f26bad511a512d2365

Just for extra proof of ownership I added a screenshot. Anything else that would help just let me know!

I am sorry, but this is not something that would be recoverable by this effort. You sent cDAI to an address unassociated with the compound protocol. That is a permeate, irreversible transaction, and the compound community can not help you recover it. We can help recover tokens sent to upgradeable contracts managed by the Compound community.

1 Like

Oof, I was so excited. It is no worries and I still genuinely appreciate how much time and effort you put into this proposal, regardless of the outcome. I wish you a good day, sir.

1 Like

I have completed development on this patch. Please review the PR linked below. The changes are quite minimal and have full testing and simulation coverage. In addition to adding the sweep function, I removed the unused verify hooks which will result in gas savings on most interactions. I don’t plan on having a formal audit, so please take a look!

2 Likes

I have deployed the new implementation here. Please match the contract to ensure the code is as expected. I plan to make a proposal post soon and get this to a proposal.

2 Likes