Skip to content

Add Resistant Balances#155

Merged
Joeysantoro merged 5 commits intofeat/v2from
feat/v2-Add-Resistant-Balances
Sep 12, 2021
Merged

Add Resistant Balances#155
Joeysantoro merged 5 commits intofeat/v2from
feat/v2-Add-Resistant-Balances

Conversation

@Joeysantoro
Copy link
Contributor

@Joeysantoro Joeysantoro commented Sep 6, 2021

Finishes the work to update all PCVDeposit contracts by adding resistant balance calls

The ETH PCV deposits use the WETH address as balanceReportedIn because ETH doesn't have an address.

The only complex resistant balance calculation is uniswap, which has a derivation in the comments.

TODO:

  • add tests
  • consider how to handle FEI PCV deposits and upgrades (possibly a wrapper/adapter)?

@eswak
Copy link
Contributor

eswak commented Sep 6, 2021

I know it's not merged yet, but if you feel like spending an afternoon with a pen & paper, would be nice to derive the formula for resistant balance of the Curve pool too

@Joeysantoro
Copy link
Contributor Author

Made wrapper to adapt existing PCV deposits without redeploying: #156

/// @notice returns a manipulation resistant account of both the balance of underlying and protocol owned FEI
/// @dev to allow compatibility with the Collateralization Oracle even though this contract isn't an IPCVDeposit
function resistantBalanceAndFei() public view returns(uint256, uint256) {
return (balance(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if protocol contracts should report their current balance of FEI instead of 0. Like there could be a weird attack where FEI is sent to the protocol contracts, and the protocol believes it is undercollateralized & mint TRIBE, where actually it is holding the FEI. At first glance this looks like an attack that is a loss for the attacker, but idk there may be some wierd interaction somewhere ?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 this is definitely something to put some thought into - though, a special version of the Bonding Curve that implements logic susceptible to this kind of attack could just override this method.

If anything, it's better to leave it as the default of zero - I cold see an attack far more likely where someone sends FEI borrowed from a lending pool to the contract, has the contract count it, and double-counts PCV this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default of 0 makes most sense in this context because the FEI is likely held as a deposit receipt in Fuse or whatever. Alternatively we could add a distinct "Fei" PCV deposit that reports in-line with expectations for FEI

/// @notice returns the resistant balance and FEI in the deposit
function resistantBalanceAndFei() public view returns (uint256, uint256) {
uint256 resistantBalance = balance();
uint256 reistantFei = isProtocolFeiDeposit ? resistantBalance : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

So, FEI deposits add 1000 FEI to PCV and 1000 FEI to protocol-owned FEI, but we'll use an oracle price of 0 for FEI, so it will add 0$ to the PCV and 1000 FEI into circulation, correct ?

Copy link
Contributor

Choose a reason for hiding this comment

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

^ this is confusing and should be very clearly spelled out in docs if we go forward with it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eswak 's comment was the intended behavior. Alternatively we can return 0 for the balance on Fei deposits to be explicit. @ditchfieldcaleb is the intended outcome confusing or just the implementation?

Copy link
Contributor

@xklob xklob left a comment

Choose a reason for hiding this comment

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

Feedback submitted. I still want to review the derivation for the Uniswap resistant balance but I'm sure its fine if it's been checked over a few times.

@Joeysantoro Joeysantoro merged commit 0aa4acd into feat/v2 Sep 12, 2021
@xklob xklob deleted the feat/v2-Add-Resistant-Balances branch September 19, 2021 18:59
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.

3 participants

Comments