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

Add LM Optimism L1 to L2 bridge interface #840

Open
wants to merge 6 commits into
base: ccip-develop
Choose a base branch
from

Conversation

ogtownsend
Copy link
Collaborator

@ogtownsend ogtownsend commented May 10, 2024

This PR adds the Optimism bridge interface for L1 to L2 transfers. Some important things to note:

  • The Optimism L1 bridge adapter increments a nonce with each transfer and each time sendERC20 is called. This nonce is included in multiple events throughout the transfer's lifecycle and is how we "match" and link events together to confirm they've reached the various states.
  • The GetTransfers() function makes use of this nonce and implements the matching logic to link these 3 events together and partition transfers into categories:
    • L1's LiquidityManager LiquidityTransferred.bridgeReturnData, which should equal
    • OP's StandardBridge event ERC20BridgeFinalized.extraData which should equal
    • L2's LiquidityManager LiquidityTransferred.bridgeSpecificData
  • See the TODO: Applying the 1.2x gas... comment on how we should think about adjusting the gas limit appropriately to account for how OP's native bridge dynamically burns gas

@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch 4 times, most recently from 100cd3b to 510e7af Compare May 17, 2024 19:43
Copy link
Contributor

github-actions bot commented May 17, 2024

LCOV of commit 8e0e3d2 during Solidity Foundry #4572

Summary coverage rate:
  lines......: 98.8% (1251 of 1266 lines)
  functions..: 96.4% (266 of 276 functions)
  branches...: 92.2% (507 of 550 branches)

Files changed coverage rate: n/a

@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch from 510e7af to d14abd3 Compare May 17, 2024 22:48
@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch from d14abd3 to 4ee8b91 Compare May 17, 2024 22:50
@ogtownsend ogtownsend changed the title [do not merge] wip [do not merge] Add LM Optimism L1 to L2 bridge interface May 17, 2024
Comment on lines +428 to +430
// TODO: what if a rebalance is triggered at T=0, the sent log is emitted at t=1
// and the DepositFinalized log is emitted at T=2, and our query goes back to T=2. There will be
// 1 DepositFinalized log and 0 sent logs. Maybe drop this condition and just do the matching
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cc @makramkd , we chatted about this in one of our meetings, I'll probably tackle this when I work on the arbitrum side of things

Comment on lines +19 to +21
// TODO: these index values might need to be updated when Ryan makes changes to the LM contract and event fields
// LiquidityTransferredToChainSelectorTopicIndex is the index of the topic in the LiquidityTransferred event
// that contains the "to" chain selector.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI @RyanRHall , these are the indices that might change once we update the contract events and may impact the log poller queries

ERC20BridgeFinalizedTopic = optimism_standard_bridge.OptimismStandardBridgeERC20BridgeFinalized{}.Topic()

// Optimism contract addresses: https://docs.optimism.io/chain/addresses
// TODO: confirm that we're able to use these L1 proxy addresses
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@makramkd or @RyanRHall do you know how often these proxy addresses change? Can we use these hardcoded proxy addresses in log poller queries reliably, or do they need to be fetched programmatically?

l1FilterName := fmt.Sprintf("OptimismL1ToL2Bridge-L1-LiquidityManager:%s-Local:%s-Remote:%s",
l1LiquidityManagerAddress.String(), localChain.Name, remoteChain.Name)

// TODO: FIXME pass valid context
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@amirylm what's the correct way to pass a context down into these bridge interfaces? I see this TODO FIXME inside the arbitrum bridges as well

Copy link
Collaborator

@amirylm amirylm May 20, 2024

Choose a reason for hiding this comment

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

We should accept a context arg in this function, that should be passed all the way from NewBridge() which currently doesn't accept a context but it should.

You can also create a ticket for fixing contexts cross the liquidity manager instead of fixing it in this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created LM-116

ctx context.Context,
transfer models.Transfer,
) ([]byte, *big.Int, error) {
// TODO: maybe add check if this is a native transfer or ERC20 transfer
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we're only transferring ERC20s (WETH) for now right?

Comment on lines +267 to +274
// TODO: Applying the 1.2x gas limit bump here to the fee won't really have an effect on the actual gas burned by
// the OP bridge since the gas units are hardcoded to 1e6 in services/relay/evm/liquidity_manager.go. We should
// instead consider a better way to dynamically bump the gas used by the transmitter, or just hardcode an even
// higher gas limit in the transmitter. The OP team has confirmed that only gas up to the "market rate" will be
// burned, not all gas remaining in the limit.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

return nil, errors.New("no transfer nonces found in bridge payloads")
}

// TODO: reconfirm that all nonces should be the same across all payloads in a given round for OP
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cc @makramkd you said this should hold true, but I wanted to reconfirm, otherwise this QuorumizedBridgePayload() function gets a little wonky since the bridgeReturnData/nonce should be unique for a given transfer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch from 4ee8b91 to d8a8145 Compare May 17, 2024 23:03
@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch from d8a8145 to 17e53fe Compare May 20, 2024 23:33
for _, pendingTransfer := range pendingTransfers {
unexecuted = append(unexecuted, pendingTransfer)
}
unexecuted := make([]liquidityrebalancer.UnexecutedTransfer, 0, len(resolvedTransfersQuorum)+len(inflightTransfers)+len(pendingTransfers))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was just a nit, felt like resolved --> inflight --> pending better represented the chronological ordering/stages that the transfers go through

@ogtownsend ogtownsend changed the title [do not merge] Add LM Optimism L1 to L2 bridge interface Add LM Optimism L1 to L2 bridge interface May 21, 2024
@ogtownsend ogtownsend marked this pull request as ready for review May 21, 2024 21:03
@ogtownsend ogtownsend force-pushed the LM-35-optimism-l-1-l-2-bridge-offchain-support branch from dd16a1b to 8e0e3d2 Compare May 21, 2024 21:23
log.Fatalf("Failed to pack depositETHTo function call: %v", err)
}

// Estimate gas needed for the depositETHTo call issued from the L1 Bridge Adapter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

update comment

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.

None yet

2 participants