Skip to main content

Compound V2 markets

OperationsLending → Compound V2 (Composer)

All Compound V2 markets behave the same way. The market is specified by the cToken parameter. Note that Compound V2 supports both native tokens (ETH) and ERC20 tokens.

Deposit

Deposit the underlying to the lender for the given cToken.

If amount=0, we use the contract balance via underlying.balanceOf(address(this)). This is recommended when executing this operation after a swap.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620cToken address

Withdraw

Withdraw from the lender. Note that this requires that the caller approved the composer to spend cToken on their behalf.

If amount=0xffffffffffffffffffffffffffff, we read the user's full balance and withdraw without leaving dust.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620cToken address

Borrow

Borrow from the lender. The prerequisite is that the caller approved the composer contract to borrow on their behalf.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620cToken address

Repay

Repay to the lender. In this case, use amount=0 to repay underlying.balanceOf(address(this)), the contract balance. If amount=0xffffffffffffffffffffffffffff, repay the minimum of the contract balance and the caller debt.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620cToken address