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 wrapper functionality & bridge integration #281

Merged
merged 47 commits into from
Feb 20, 2025

Conversation

loic1
Copy link
Contributor

@loic1 loic1 commented Feb 7, 2025

Changes:

  • Update FlowEVM TopShot contract code:
    • Extend ERC721Wrapper OpenZeppelin library
    • Remove ERC721URIStorage extension (per-token metadata storage isn't currently needed) and use baseTokenURI contract state variable instead to build metadata endpoint url from tokenURI with token ID
    • Extend BridgePermissionsUpgradeable to prevent bridge onboarding before bridge upgrade
    • Extend CrossVMBridgeFulfillmentUpgradeable to allow upgraded bridge to fulfill to EVM (i.e., mint or transfer)
  • Add Cadence bridging & wrapping txs

struct RoyaltyInfo {
address royaltyAddress;
uint96 royaltyBps;
}

/**
* @dev Initializes the contract.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added contract init params: underlyingNftContractAddress, vmBridgeAddress, baseTokenURI_

@@ -73,31 +117,33 @@ contract BridgedTopShotMoments is
return _customSymbol;
}

function safeMint(address to, uint256 tokenId, string memory uri) public onlyOwner {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed safeMint - minting will only be possible as part of:

  1. Wrapper functionality
  2. Bridge fulfillment (when contract is onboarded to upgraded bridge)


import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

interface IBridgePermissions is IERC165 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From flow-evm-bridge repo

@@ -0,0 +1,6 @@
pragma solidity 0.8.24;

interface ICrossVMBridgeFulfillment {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interface conformance expected to be needed to onboard a custom contract in upcoming upgraded bridge

* Note: The Flow VM bridge checks for permissions at asset onboarding. If your asset has already
* been onboarded, setting `permissions` to `false` will not affect movement between VMs.
*/
abstract contract BridgePermissionsUpgradeable is Initializable, ERC165Upgradeable, IBridgePermissions {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From flow-evm-bridge repo

* @dev A base contract intended for use in implementations on Flow, allowing a contract to define
* access to the Cadence X EVM bridge on certain methods.
*/
abstract contract CrossVMBridgeCallableUpgradeable is ContextUpgradeable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adapted for upgradable contracts from flow-evm-repo draft PR - the functionality is what's currently expected to register a custom contract in upcoming upgraded bridge

import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
import {ICrossVMBridgeFulfillment} from "../interfaces/ICrossVMBridgeFulfillment.sol";

abstract contract CrossVMBridgeFulfillmentUpgradeable is CrossVMBridgeCallableUpgradeable, ERC165Upgradeable, ERC721Upgradeable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adapted for upgradable contracts from flow-evm-repo draft PR - the functionality is what's currently expected to register a custom contract in upcoming upgraded bridge

}
return nil
}

// resolveCrossVMPointerView resolves the CrossVMPointer view
// access(all) view fun resolveCrossVMPointerView(): MetadataViews.CrossVMPointer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented out until this PR's changes are merged and pushed on-chain - this new metadata view should be returned both from contract and nft metadata views; this should provide the custom contract FlowEVM address

import "FlowEVMBridgeConfig"
import "FlowEVMBridgeUtils"

/// Bridges NFTs with provided IDs from Cadence to EVM and wraps them in a wrapper ERC721
Copy link
Contributor Author

@loic1 loic1 Feb 10, 2025

Choose a reason for hiding this comment

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

All-in-one Cadence tx to bridge NFTs from Cadence to EVM and make EVM contract calls to approve wrapper erc721 contract as operator and wrap the bridged NFTs to wrapper erc721 NFTs

Adapted from flow-evm-bridge's batch_bridge_nft_to_evm.cdc

/// @param nftIDs: Array of IDs of the NFTs to wrap
///
transaction(
wrapperERC721Address: String,
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 parameter should not be needed anymore once we can get the contract address from new metadata view on-chain

@loic1 loic1 marked this pull request as ready for review February 10, 2025 21:52
@loic1 loic1 requested a review from a team as a code owner February 10, 2025 21:52
@loic1 loic1 changed the title Implement wrapper functionality Add wrapper functionality & bridge integration Feb 10, 2025
@loic1 loic1 requested review from judezhu, Deewai and vdojnov February 10, 2025 22:07
@loic1 loic1 changed the base branch from loic/add-creator-token-implementation to evm-bridging February 17, 2025 22:47
@loic1
Copy link
Contributor Author

loic1 commented Feb 19, 2025

Key Updates:

  • Added EVMPointer view support for newly deployed CrossVMMetadataViews (uncommented previously pushed changes)
    • Uses placeholder for custom erc721 address until the actual testnet and mainnet contracts are deployed
    • Added local test dependency handling
  • Updated txs to wrap/unwrap only when applicable and to transfer to optional provided evm address (with separate util methods)
  • Added tx fixes & improvements, withdrawTo/depositFor return checks, safeTransferFrom ownership checks - based on PR feedback + testing

@loic1 loic1 requested a review from vdojnov February 19, 2025 22:06
return decodedResult[0] as! EVM.EVMAddress
}

/// Calls a function on an EVM contract from provided coa
Copy link
Contributor

Choose a reason for hiding this comment

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

so we decided not to deploy an util contract for the mustCall function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea it would be best achieved by holding the contract in a trusted neutral entity like the bridge account or a keyless account given the privileged access to COA, but it doesn't seem really worth it at this point as the wrapping/unwrapping logic is needed only temporarily until the bridge gains support for custom associations and unwrapping logic within its own context

Copy link
Contributor

@judezhu judezhu left a comment

Choose a reason for hiding this comment

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

LGTM! left one question

@loic1 loic1 merged commit d6c8835 into evm-bridging Feb 20, 2025
1 check passed
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.

5 participants