LayerZero-Labs / LayerZero-v2

Other
542 stars 327 forks source link

Added upgradeable variant of OApp #9

Closed Zodomo closed 8 months ago

Zodomo commented 9 months ago

We needed the ability to make an upgradeable OApp for our L0 V2 integration, so I refactored OApp to utilize OpenZeppelin's OwnableUpgradeable.sol and the initialize pattern in place of the non-upgradeable Ownable.sol variant.

St0rmBr3w commented 8 months ago

Thank you for the contribution! I think this should live outside of this repo as a third-party extension of the OApp Standard.

In general, the LayerZero Labs team does not recommend creating an upgradeable OApp contract variant due to the complexity of maintaining upgradeable contracts on multiple chains, which can introduce potential race conditions in your development.

Ultimately it's up to teams to decide which approach works best for their project, but we choose not to endorse upgradeable OApps for that reason. Please feel free to maintain externally though!

JorgeAtPaladin commented 8 months ago

@Zodomo a potential middle ground for you could be to have a non-upgreadable "messenger" interface contract (the oapp) that plugs into your upgradeable app contract, then you could have a setMessenger() or something to upgrade it through redeployment.

Zodomo commented 8 months ago

@Zodomo a potential middle ground for you could be to have a non-upgreadable "messenger" interface contract (the oapp) that plugs into your upgradeable app contract, then you could have a setMessenger() or something to upgrade it through redeployment.

@JorgeAtPaladin thanks for the input! In our case, our core application is ownerless and nonupgradeable, so we've elected to externalize the bridge functionality into a separate upgradeable contract. For our setup, making OApp upgradeable seemed to be the best option. That being said, paring down our existing bridge endpoint to just acting as a messenger between the main protocol and the nonupgradeable OApp might be a worthwhile idea.

e00dan commented 8 months ago

@Zodomo I had very similar requirements as you did. I just noticed your pull request. Maybe if I noticed it earlier it would save me some work. : D

I created this starter kit repository with upgradeability out of the box and native Foundry approach: https://github.com/Kuzirashi/layerzero-starter-kit

I also have a weird feeling when cloning official LZ repository with all the protocol contracts just to deploy a counter or custom app. I feel like small external Foundry + LZ boilerplate repository could be easier to start development, but that's just my personal preference.


Edit:

I've decided to use these smart contracts in my starter kit repository, because I think this implementation looks a bit better than what I had originally.