Skip to content

Conversation

@viatrix
Copy link
Collaborator

@viatrix viatrix commented Feb 10, 2025

Closes: #4

@lastperson lastperson added this to the Liquidity MVP milestone Feb 13, 2025
@lastperson lastperson linked an issue Feb 13, 2025 that may be closed by this pull request
@lastperson lastperson marked this pull request as ready for review February 13, 2025 12:49
@lastperson lastperson merged commit 7f7b5cc into main Feb 13, 2025
3 checks passed
$.mpcAddress = mpcAddress_;
}

function deposit() external override {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also have a deposit method with pull USDC mechanic? For bridging?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will add

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mpetrunic could you add more details? Do you mean deposit with transferFrom? Currently bridging mechanic is already in place. Rebalancer transfers funds to the liquidity pool then calls deposit().

Copy link
Member

Choose a reason for hiding this comment

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

Just create another method that receives argument amount and pulls funds from caller

Copy link
Member

Choose a reason for hiding this comment

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

All deposits should always take amount input so to prevent depositing profit as collateral

uint256 amount = COLLATERAL.balanceOf(address(this));
require(amount > 0, NoCollateral());
IAavePool pool = IAavePool(AAVE_POOL_PROVIDER.getPool());
(, uint256 repaidAmount) = _repay(address(COLLATERAL), pool, true);
Copy link
Member

Choose a reason for hiding this comment

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

whats the reasoning behind this?

Like, I think it will cause bugs. We have a cron job that calls repayment. If you repay with a deposit, later on when we get repayment, we will consider it profit and not collateral

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently the collateral (usdc) cannot be withdrawn as profit. It can be supplied to aave, used for repayments and withdrawn from aave. Please correct us if the flow should be different

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mpetrunic this really depends on how you are planning to do the offchain accounting. Lets discuss what needs to be accounted, then come up with a robust solution. We can do the accounting inside the contract ofcourse, but that will use more gas.

Copy link
Member

Choose a reason for hiding this comment

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

conclusion: remove repay with collateral

// the operation securely.
(bool success,) = target.call(targetCallData);
require(success, TargetCallFailed());
emit Borrowed(borrowToken, amount, msg.sender, target, targetCallData);
Copy link
Member

Choose a reason for hiding this comment

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

this method needs to be really gas optimized, so I would avoid emitting event

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove, sure.


// Admin functions

function withdraw(address to, uint256 amount) external override onlyRole(LIQUIDITY_ADMIN_ROLE) returns (uint256) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think admin should be allowed to withdraw collateral. Only rebalancer should be able to withdraw to transfer to different chain.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That role is just called liquidity admin, which is given to rebalancer and hub.

return withdrawn;
}

function withdrawProfit(
Copy link
Member

Choose a reason for hiding this comment

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

hmm I don't think this is gonna work. We will most likely always have debt > profit as we are always solving something.
Which means we will never be able to withdraw profit.

From my pov we have two options. We can pause contract and only allow withdrawal once all debt has been repaid.

When borrowing, we submit signed input amount and track profit on the contract.

I'm more in favour of option #1 because of gas and ease of implementation

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we have debt > profit, then maybe we can assume that there is not enough profit worth withdrawing?

Copy link
Member

Choose a reason for hiding this comment

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

Conclusion:

  • add pause functionality
  • prevent withdraw if there is a debt for token we are trying to withdraw
  • prevent withdrawing aUSDC token (collateral ownership)
  • change interface to just accept list of token addresses (transfer full amount)
  • allows usdc withdrawal as profit

Q: can we make LiquidityPool not upgradable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Liquidity Pool

4 participants