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

Compoundv2 #3

Merged
merged 29 commits into from
Sep 25, 2023
Merged

Compoundv2 #3

merged 29 commits into from
Sep 25, 2023

Conversation

uneventfulhorizon
Copy link
Contributor

Now with working tests

emit Claim(msg.sender, userClaim);

// Cap the user's claim to the available balance of cUSDC tokens
if (_amount > userClaim) _amount = userClaim;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will create confusing UX. Just revert in case amount provided is > than balance

"USDC balance of CUSDC: %s",
USDC.balanceOf(address(CUSDC))
);
console2.log(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove console logs from tests :)

// @param to The address to which the GRO position will be transferred.
// @param amount The amount of GRO to transfer.
function transferPosition(address _to, uint256 _amount) public {
if (_amount > (_userGROBalance[msg.sender] - _userClaims[msg.sender]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this one is mixing apples with oranges? _userGROBalance is denominated in GRO tokens, _userClaims is denominated in USDC?

if (_amount > userClaim) _amount = userClaim;

// Revert if nothing to claim
if (_amount == 0) revert RedemptionErrors.InsufficientBalance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be checked at the very top to avoid spending gas if _amount provided is 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the current location it also reverts if userClaim is 0 - if you move it to top then it won't revert when userClaim is 0

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does, but that requires additional SLOAD. Func parameters should be checked at the very top because they are very cheap to check if you need to revert

revert RedemptionErrors.USDCRedeemFailed(redeemResult);

uint256 usdcAmount = (ICERC20(CUSDC).exchangeRateStored() * _amount) /
1e20;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why 1e20 ? Can it be moved to constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because:
USDC 1e6 = (CUSDC 1e8 * exchangeRate 1e18) / 1ePRECISION
PRECISION = 20

yeah - should be in constants

Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, why don't we transfer all USDC redeemed but trying to calculate it after we redeem?

if (redeemResult != 0)
revert RedemptionErrors.USDCRedeemFailed(redeemResult);

uint256 usdcAmount = (ICERC20(CUSDC).exchangeRateStored() * _amount) /
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you think we should transfer 100% of USDC balance redeemed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Means an additional sload for balanceOf, but probably safer to avoid someone not getting USDC after a rounding error

@SHAKOTN SHAKOTN merged commit 20eabcc into main Sep 25, 2023
1 check passed
@SHAKOTN SHAKOTN deleted the compoundv2 branch September 25, 2023 14:14
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