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

Update README #21

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
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
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# CometWrapper
# Comet Wrapper

A wrapped token for any of the Compound III tokens.
A wrapped token that converts a rebasing [Compound III](https://github.com/compound-finance/comet) token into a non-rebasing [ERC-4626](https://eips.ethereum.org/EIPS/eip-4626) vault with [ERC-7246](https://github.com/ethereum/EIPs/pull/7246) ([Encumber](https://blog.compoundlabs.xyz/)) support.

## Overview

Compound III tokens like cUSDCv3 and cWETHv3 are rebasing tokens, which means the token balances automatically increase as interest is accrued. However, most protocols are designed to work with non-rebasing tokens. The standard solution to this problem is to use a wrapped token.

This wrapped token allows other protocols to more easily integrate with Compound III tokens and treat it like any standard ERC20 token.

## Features

- **ERC-4626 support**: Converts a Compound III token into a non-rebasing ERC-4626 vault.
- **ERC-7246 (Encumber) support**: The wrapper implements encumberability, which allows it to be used non-custodially in supported protocols.
- **Liquidity mining incentives tracking**: Users that deposit into the wrapper will earn their respective share of incentives for markets that provide them.
- **Signature based operations**: Users can approve and encumber their wrapper tokens gaslessly using signatures.
- **Signature verification for contracts**: All by-signature functions (`permit`, `encumberBySig`) support [EIP-1271](https://eips.ethereum.org/EIPS/eip-1271) signature verification, meaning smart contract wallets can interact with the wrapper through signatures.
- **Controlled by Compound governance**: Each wrapper contract is deployed behind an upgradeable proxy that is managed by Compound governance.

## Design Decisions

`CometWrapper` is designed to nullify [inflation attacks](https://blog.openzeppelin.com/a-novel-defense-against-erc4626-inflation-attacks) which could cause losses for users. It's a method of manipulating the exchange rate of wrapped tokens which enables attackers to steal the underlying tokens from target depositors or make it prohibitively expensive for future depositors to use the contract.

To nullify inflation attacks, `CometWrapper` maintains internal accounting of all Compound III tokens deposited and withdrawn. This internal accounting only gets updated through the `mint`, `redeem`, `deposit` and `withdraw` functions. This means that any direct transfer of Compound III tokens will not be recognized by the `CometWrapper` contract. The tradeoff is that any tokens directly transferred to `CometWrapper` will be locked.

## Deployments

Expand All @@ -14,34 +35,13 @@ A wrapped token for any of the Compound III tokens.
| Base | USDC | Upcoming |
| Base | WETH | Upcoming |

## Overview

Compound III tokens like cUSDCv3 and cWETHv3 are rebasing tokens. Protocols are designed to work with tokens that do not automatically increase balances like rebasing tokens do. The standard solution to this problem is to use a wrapped token.
This wrapped token allows other protocols to more easily integrate with Compound III tokens and treat it like any standard ERC20 token.

## Design Decisions

`CometWrapper` was designed to nullify inflation attacks which could cause losses for users. It's a method of manipulating the price of Wrapped tokens which enables attackers to steal underlying tokens from target depositors or make it prohibitively expensive for future depositors to use the contract.

To nullify inflation attacks, `CometWrapper` maintains internal accounting of all Compound III tokens deposited and withdrawn. This internal accounting only gets updated through the functions `mint`, `redeem`, `deposit` and `withdraw`. This means that any direct transfer of Compound III tokens will not be recognized by the `CometWrapper` contract to prevent malicious actors from manipulating the exchange rate of Wrapped Compound III token to the actual Compound III token. The tradeoff is that any tokens directly transferred to `CometWrapper` will be forever locked and unrecoverable.

### Shares Redemption

When doing Comet transfers, Comet may decrease sender's principal by 1 more than the specified amount in favor of the receiver. To take into account this quirk of Comet transfers, this CometWrapper will always transfer assets worth `shares - 1` and burn `shares` amount when calling `redeem`.

In this way, any rounding error would be in favor of CometWrapper and at the expense of users. The loss for users is negligible since it is only 1 unit of Wrapped cUSDCv3. However, this serves as protection against insolvency for CometWrapper so that it nevers ends up in a state where users' total shares is greater than the total supply of Wrapped cUSDCv3. Note that the loss of 1 share does not always happen for every redeem and in some cases the decrease in shares for the user and the contract is equal.

### Non-standard ERC-4626 Behavior

`mint` and `redeem` will not result in exactly `shares` amount of shares minted or redeemed, which is the standard behavior for ERC-4626. This is because CometWrapper uses `userBasic.principal` in Comet to represent `shares` and they map 1:1. Since principal in Comet may round up during transfers or round down during Comet.deposit() or Comet.withdraw(), shares minted or redeemed will have the same behavior. This tradeoff is done so we may maintain the invariant that `totalSupply` of shares in CometWrapper is always equal to the CometWrapper's `userBasic.principal` in Comet.

## Usage

`CometWrapper` implements the ERC4626 Tokenized Vault Standard and is used like any other ERC4626 contracts.
`CometWrapper` implements the ERC-4626 Tokenized Vault Standard and is used like any other ERC-4626 contracts.

### Wrapping Tokens

To wrap a Compound III token like cUSDCv3, you will need to have cUSDCv3 balance in your wallet and then do the following:
To wrap a Compound III token like cUSDCv3, you will need to have cUSDCv3 in your wallet and then do the following:

1. `comet.allow(cometWrapperAddress, true)` - allow CometWrapper to move your cUSDCv3 tokens from your wallet to the CometWrapper contract when you call `deposit` or `mint`.
2. `cometWrapper.mint(amount, receiver)` - the first parameter is the amount of Wrapped tokens to be minted.
Expand All @@ -56,4 +56,4 @@ To withdraw a Compound III token like cUSDCv3, you may use either `withdraw` or

### Claiming Rewards

Comet tokens deposited in CometWrapper will continue to accrue rewards if reward accrual is enabled in Comet. CometWrapper keeps track of users' rewards and users would earn rewards as they would in Comet. The only difference is in claiming of the rewards. Instead of claiming rewards from the CometRewards contract, users will claim it from CometWrapper like so `cometWrapper.claimTo(alice)`.
Comet tokens deposited in CometWrapper will continue to accrue rewards if reward accrual is enabled in Comet. CometWrapper keeps track of users' rewards and users will earn rewards as they would in Comet. The only difference is in claiming of the rewards. Instead of claiming rewards from the CometRewards contract, users will claim it from CometWrapper like so `cometWrapper.claimTo(alice)`.