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

[lock/unlock]: support multi-stage finalization in rebalancer contract #613

Merged
merged 38 commits into from
Apr 24, 2024

Conversation

makramkd
Copy link
Contributor

@makramkd makramkd commented Mar 14, 2024

Motivation

PR #606 implements multi-stage finalization in the Optimism L1 bridge adapter, however this is not functional end-to-end because the Rebalancer assumes that finalization happens in a single step.

Solution

Change the bridge adapter interface to return a boolean from finalizeWithdrawERC20 that indicates whether the funds are available for use by the rebalancer.

The rest of the changes are to get test coverage for this new interface change.

Copy link
Contributor

LCOV of commit c533064 during Solidity Foundry #3154

Summary coverage rate:
  lines......: 98.6% (935 of 948 lines)
  functions..: 95.1% (195 of 205 functions)
  branches...: 91.9% (364 of 396 branches)

Files changed coverage rate: n/a

## Motivation

Optimism ETH transfers need to be rewrapped before we can inject them
into the token pool.

## Solution

Add a parameter to the `ReceiveLiquidityParams` that indicates whether
the Rebalancer contract should re-wrap native after executing a
finalization.

It is expected that the caller knows what they are doing (i.e DON or
owner).
Copy link
Contributor

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset.

Copy link
Contributor

I see you updated files related to contracts. Please run pnpm changeset in the contracts directory to add a changeset.

s_nonceUsed[nonce] = true;
i_token.safeTransfer(localReceiver, amount);
) external override returns (bool) {
Payload memory payload = abi.decode(bridgeSpecificPayload, (Payload));
Copy link
Collaborator

@matYang matYang Apr 24, 2024

Choose a reason for hiding this comment

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

nit: wow! ik it's a mock, but still let's use return early to reduce some nesting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@@ -115,9 +144,10 @@ contract Rebalancer__report is RebalancerSetup {
}

contract Rebalancer_rebalanceLiquidity is RebalancerSetup {
uint256 internal constant AMOUNT = 12345679;
Copy link
Collaborator

@matYang matYang Apr 24, 2024

Choose a reason for hiding this comment

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

static AMOUNT implies these are good fuzz candidates, let's add some fuzzing? =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are potentially opportunities for fuzzing, but I don't think the current tests are useful to make fuzzes. They basically just deal this AMOUNT to the pool and run through the rebalancing process.

Adding fuzz tests is on the docket though, we have tickets for that.

// approve and liquidity container should transferFrom
// if we reach this point, the finalization failed.
// since we don't have enough information to know why it failed,
// we assume that it failed because the withdrawal was already finalized,
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of assuming, let's explain why this will always be safe to call injectLiquidity here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic will change in upcoming PRs after recent reviews, so stay tuned.

@@ -4,15 +4,15 @@ pragma solidity 0.8.19;
import {IBridgeAdapter} from "./interfaces/IBridge.sol";
import {IRebalancer} from "./interfaces/IRebalancer.sol";
import {ILiquidityContainer} from "./interfaces/ILiquidityContainer.sol";

import {IWrappedNative} from "../ccip/interfaces/IWrappedNative.sol";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit newline after interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍

@@ -258,6 +298,11 @@ contract Rebalancer is IRebalancer, OCR3Base {
);
}

function _wrapNative(uint256 amount) private {
IWrappedNative weth = IWrappedNative(address(i_localToken));
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove assignment and inline. Might as well remove the function and just inline the single line at that point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined 👍

return _proveWithdrawal(payload);
} else if (payload.action == FinalizationAction.FinalizeWithdrawal) {
return _finalizeWithdrawal(payload, localReceiver);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit else can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Axed 🪓

@makramkd makramkd merged commit 24133f9 into ccip-develop Apr 24, 2024
81 checks passed
@makramkd makramkd deleted the makram/CCIP-1438/rebalancer-changes branch April 24, 2024 10:09
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.

4 participants