Skip to content

Commit

Permalink
Merge pull request #28 from onflow/add-ft-bridge
Browse files Browse the repository at this point in the history
Add fungible token support
  • Loading branch information
sisyphusSmiling authored Apr 15, 2024
2 parents 5d36089 + c1cc1aa commit 9b6dc21
Show file tree
Hide file tree
Showing 63 changed files with 3,589 additions and 491 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ db/
# Cadence test framework coverage
coverage.json
coverage.lcov

# Keys
*.pkey
*.pem
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
![Tests](https://github.com/onflow/flow-evm-bridge/actions/workflows/cadence_test.yml/badge.svg)
[![codecov](https://codecov.io/gh/onflow/flow-evm-bridge/graph/badge.svg?token=C1vCK0t88F)](https://codecov.io/gh/onflow/flow-evm-bridge)

# [WIP] Flow EVM Bridge

> :warning: This repo is a work in progress :building_construction:
Expand All @@ -13,8 +16,7 @@ As the bridge contracts are still in development, builders should be aware that
Install an EVM-compatible pre-release version of the Flow CLI (currently [v1.12.0-cadence-v1.0.0-M8-2](https://github.com/onflow/flow-cli/releases/tag/v1.12.0-cadence-v1.0.0-M8-2)):

```sh
sudo sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" \
-- v1.12.0-cadence-v1.0.0-M8-2
sudo sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
```

If you wish to interact with the contracts from the EVM side, this repo is configured for use with Foundry. See [Foundry's installation docs](https://book.getfoundry.sh/getting-started/installation) for more information.
Expand Down
27 changes: 21 additions & 6 deletions cadence/args/bridged-nft-code-chunks-args.json

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions cadence/args/bridged-token-code-chunks-args.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions cadence/args/deploy-erc20-args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"type": "String",
"value": "6101606040523480156200001257600080fd5b50604051806040016040528060048152602001634e414d4560e01b81525080604051806040016040528060018152602001603160f81b81525033604051806040016040528060048152602001634e414d4560e01b8152506040518060400160405280600681526020016514d6535093d360d21b815250816003908162000099919062000318565b506004620000a8828262000318565b5050506001600160a01b038116620000db57604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b620000e681620001a3565b50620000f4826006620001f5565b6101205262000105816007620001f5565b61014052815160208084019190912060e052815190820120610100524660a0526200019360e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c052506200045a565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600060208351101562000215576200020d836200022e565b905062000228565b8162000222848262000318565b5060ff90505b92915050565b600080829050601f815111156200025c578260405163305a27a960e01b8152600401620000d29190620003e4565b8051620002698262000435565b179392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200029c57607f821691505b602082108103620002bd57634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111562000313576000816000526020600020601f850160051c81016020861015620002ee5750805b601f850160051c820191505b818110156200030f57828155600101620002fa565b5050505b505050565b81516001600160401b0381111562000334576200033462000271565b6200034c8162000345845462000287565b84620002c3565b602080601f8311600181146200038457600084156200036b5750858301515b600019600386901b1c1916600185901b1785556200030f565b600085815260208120601f198616915b82811015620003b55788860151825594840194600190910190840162000394565b5085821015620003d45787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60006020808352835180602085015260005b818110156200041457858101830151858201604001528201620003f6565b506000604082860101526040601f19601f8301168501019250505092915050565b80516020808301519190811015620002bd5760001960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051611147620004b5600039600061093101526000610904015260006107c101526000610799015260006106f40152600061071e0152600061074801526111476000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c8063715018a6116100ad57806395d89b411161007157806395d89b4114610258578063a9059cbb14610260578063d505accf14610273578063dd62ed3e14610286578063f2fde38b146102bf57600080fd5b8063715018a6146101f457806379cc6790146101fc5780637ecebe001461020f57806384b0196e146102225780638da5cb5b1461023d57600080fd5b8063313ce567116100f4578063313ce5671461018c5780633644e5151461019b57806340c10f19146101a357806342966c68146101b857806370a08231146101cb57600080fd5b806306fdde0314610126578063095ea7b31461014457806318160ddd1461016757806323b872dd14610179575b600080fd5b61012e6102d2565b60405161013b9190610e91565b60405180910390f35b610157610152366004610ec7565b610364565b604051901515815260200161013b565b6002545b60405190815260200161013b565b610157610187366004610ef1565b61037e565b6040516012815260200161013b565b61016b6103a2565b6101b66101b1366004610ec7565b6103b1565b005b6101b66101c6366004610f2d565b6103c7565b61016b6101d9366004610f46565b6001600160a01b031660009081526020819052604090205490565b6101b66103d4565b6101b661020a366004610ec7565b6103e8565b61016b61021d366004610f46565b6103fd565b61022a61041b565b60405161013b9796959493929190610f61565b6005546040516001600160a01b03909116815260200161013b565b61012e610461565b61015761026e366004610ec7565b610470565b6101b6610281366004610ffa565b61047e565b61016b61029436600461106d565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6101b66102cd366004610f46565b6105bd565b6060600380546102e1906110a0565b80601f016020809104026020016040519081016040528092919081815260200182805461030d906110a0565b801561035a5780601f1061032f5761010080835404028352916020019161035a565b820191906000526020600020905b81548152906001019060200180831161033d57829003601f168201915b5050505050905090565b6000336103728185856105f8565b60019150505b92915050565b60003361038c85828561060a565b610397858585610688565b506001949350505050565b60006103ac6106e7565b905090565b6103b9610812565b6103c3828261083f565b5050565b6103d13382610875565b50565b6103dc610812565b6103e660006108ab565b565b6103f382338361060a565b6103c38282610875565b6001600160a01b038116600090815260086020526040812054610378565b60006060806000806000606061042f6108fd565b61043761092a565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6060600480546102e1906110a0565b600033610372818585610688565b834211156104a75760405163313c898160e11b8152600481018590526024015b60405180910390fd5b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886104f48c6001600160a01b0316600090815260086020526040902080546001810190915590565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050600061054f82610957565b9050600061055f82878787610984565b9050896001600160a01b0316816001600160a01b0316146105a6576040516325c0072360e11b81526001600160a01b0380831660048301528b16602482015260440161049e565b6105b18a8a8a6105f8565b50505050505050505050565b6105c5610812565b6001600160a01b0381166105ef57604051631e4fbdf760e01b81526000600482015260240161049e565b6103d1816108ab565b61060583838360016109b2565b505050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114610682578181101561067357604051637dc7a0d960e11b81526001600160a01b0384166004820152602481018290526044810183905260640161049e565b610682848484840360006109b2565b50505050565b6001600160a01b0383166106b257604051634b637e8f60e11b81526000600482015260240161049e565b6001600160a01b0382166106dc5760405163ec442f0560e01b81526000600482015260240161049e565b610605838383610a87565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561074057507f000000000000000000000000000000000000000000000000000000000000000046145b1561076a57507f000000000000000000000000000000000000000000000000000000000000000090565b6103ac604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b6005546001600160a01b031633146103e65760405163118cdaa760e01b815233600482015260240161049e565b6001600160a01b0382166108695760405163ec442f0560e01b81526000600482015260240161049e565b6103c360008383610a87565b6001600160a01b03821661089f57604051634b637e8f60e11b81526000600482015260240161049e565b6103c382600083610a87565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60606103ac7f00000000000000000000000000000000000000000000000000000000000000006006610bb1565b60606103ac7f00000000000000000000000000000000000000000000000000000000000000006007610bb1565b60006103786109646106e7565b8360405161190160f01b8152600281019290925260228201526042902090565b60008060008061099688888888610c5c565b9250925092506109a68282610d2b565b50909695505050505050565b6001600160a01b0384166109dc5760405163e602df0560e01b81526000600482015260240161049e565b6001600160a01b038316610a0657604051634a1406b160e11b81526000600482015260240161049e565b6001600160a01b038085166000908152600160209081526040808320938716835292905220829055801561068257826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610a7991815260200190565b60405180910390a350505050565b6001600160a01b038316610ab2578060026000828254610aa791906110da565b90915550610b249050565b6001600160a01b03831660009081526020819052604090205481811015610b055760405163391434e360e21b81526001600160a01b0385166004820152602481018290526044810183905260640161049e565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b038216610b4057600280548290039055610b5f565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610ba491815260200190565b60405180910390a3505050565b606060ff8314610bcb57610bc483610de4565b9050610378565b818054610bd7906110a0565b80601f0160208091040260200160405190810160405280929190818152602001828054610c03906110a0565b8015610c505780601f10610c2557610100808354040283529160200191610c50565b820191906000526020600020905b815481529060010190602001808311610c3357829003601f168201915b50505050509050610378565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115610c975750600091506003905082610d21565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015610ceb573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610d1757506000925060019150829050610d21565b9250600091508190505b9450945094915050565b6000826003811115610d3f57610d3f6110fb565b03610d48575050565b6001826003811115610d5c57610d5c6110fb565b03610d7a5760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115610d8e57610d8e6110fb565b03610daf5760405163fce698f760e01b81526004810182905260240161049e565b6003826003811115610dc357610dc36110fb565b036103c3576040516335e2f38360e21b81526004810182905260240161049e565b60606000610df183610e23565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600060ff8216601f81111561037857604051632cd44ac360e21b815260040160405180910390fd5b6000815180845260005b81811015610e7157602081850181015186830182015201610e55565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000610ea46020830184610e4b565b9392505050565b80356001600160a01b0381168114610ec257600080fd5b919050565b60008060408385031215610eda57600080fd5b610ee383610eab565b946020939093013593505050565b600080600060608486031215610f0657600080fd5b610f0f84610eab565b9250610f1d60208501610eab565b9150604084013590509250925092565b600060208284031215610f3f57600080fd5b5035919050565b600060208284031215610f5857600080fd5b610ea482610eab565b60ff60f81b881681526000602060e06020840152610f8260e084018a610e4b565b8381036040850152610f94818a610e4b565b606085018990526001600160a01b038816608086015260a0850187905284810360c08601528551808252602080880193509091019060005b81811015610fe857835183529284019291840191600101610fcc565b50909c9b505050505050505050505050565b600080600080600080600060e0888a03121561101557600080fd5b61101e88610eab565b965061102c60208901610eab565b95506040880135945060608801359350608088013560ff8116811461105057600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561108057600080fd5b61108983610eab565b915061109760208401610eab565b90509250929050565b600181811c908216806110b457607f821691505b6020821081036110d457634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561037857634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fdfea2646970667358221220f1e9d08ff3a77a5dedf27b973e8f3f8da74683e415389a21794cdc5ebb196f9164736f6c63430008170033"
},
{
"type": "UInt64",
"value": "12000000"
},
{
"type": "UFix64",
"value": "0.0"
}
]
2 changes: 1 addition & 1 deletion cadence/args/deploy-factory-args.json

Large diffs are not rendered by default.

70 changes: 26 additions & 44 deletions cadence/contracts/bridge/CrossVMNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@ import "MetadataViews"

import "EVM"

/// Contract defining cross-VM NFT & Collection interfaces
/// Contract defining cross-VM NFT-related interfaces & Metadata views
///
access(all)
contract CrossVMNFT {
access(all) contract CrossVMNFT {

/// A struct to represent a general case URI, used to represent the URI of the NFT where the type of URI is not
/// able to be determined (i.e. HTTP, IPFS, etc.)
///
access(all)
struct URI : MetadataViews.File {
access(all) struct URI : MetadataViews.File {
/// The base URI prefix, if any. Not needed for all URIs, but helpful for some use cases
/// For example, updating a whole NFT collection's image host easily
access(all)
let baseURI: String?
access(all) let baseURI: String?
/// The URI value
/// NOTE: this is set on init as a concatenation of the baseURI and the value if baseURI != nil
access(self)
let value: String
access(self) let value: String

access(all)
view fun uri(): String {
access(all) view fun uri(): String {
return self.value
}

Expand All @@ -36,19 +31,15 @@ contract CrossVMNFT {

/// Proof of concept metadata to represent the ERC721 values of the NFT
///
access(all)
struct EVMBridgedMetadata {
access(all) struct EVMBridgedMetadata {
/// The name of the NFT
access(all)
let name: String
access(all) let name: String
/// The symbol of the NFT
access(all)
let symbol: String
/// The URI of the NFT - this can either be contract-level or token-level URI depending on where the metadata
access(all) let symbol: String
/// The URI of the asset - this can either be contract-level or token-level URI depending on where the metadata
/// is requested. See the ViewResolver contract interface to discover how contract & resource-level metadata
/// requests are handled.
access(all)
let uri: {MetadataViews.File}
access(all) let uri: {MetadataViews.File}

init(name: String, symbol: String, uri: {MetadataViews.File}) {
self.name = name
Expand All @@ -65,38 +56,29 @@ contract CrossVMNFT {
/// See discussion https://github.com/onflow/flow-nft/pull/126#discussion_r1462612559 where @austinkline raised
/// differentiating IDs in a minimal interface incorporated into the one below
///
access(all)
resource interface EVMNFT : NonFungibleToken.NFT {
access(all)
let evmID: UInt256
access(all)
let name: String
access(all)
let symbol: String
access(all)
view fun tokenURI(): String
access(all)
view fun getEVMContractAddress(): EVM.EVMAddress
access(all) resource interface EVMNFT : NonFungibleToken.NFT {
access(all) let evmID: UInt256

access(all) view fun getName(): String
access(all) view fun getSymbol(): String
access(all) view fun tokenURI(): String
access(all) view fun getEVMContractAddress(): EVM.EVMAddress
}

/// A simple interface for a collection of EVMNFTs
///
access(all)
resource interface EVMNFTCollection {
access(all)
view fun getEVMIDs(): [UInt256]
access(all)
view fun getCadenceID(from evmID: UInt256): UInt64?
access(all)
view fun getEVMID(from cadenceID: UInt64): UInt256?
access(all)
view fun contractURI(): String?
access(all) resource interface EVMNFTCollection : NonFungibleToken.Collection {
access(all) view fun getName(): String
access(all) view fun getSymbol(): String
access(all) view fun getEVMIDs(): [UInt256]
access(all) view fun getCadenceID(from evmID: UInt256): UInt64?
access(all) view fun getEVMID(from cadenceID: UInt64): UInt256?
access(all) fun contractURI(): String?
}

/// Retrieves the EVM ID of an NFT if it implements the EVMNFT interface, returning nil if not
///
access(all)
view fun getEVMID(from token: &{NonFungibleToken.NFT}): UInt256? {
access(all) view fun getEVMID(from token: &{NonFungibleToken.NFT}): UInt256? {
if let evmNFT = token as? &{EVMNFT} {
return evmNFT.evmID
}
Expand Down
20 changes: 20 additions & 0 deletions cadence/contracts/bridge/CrossVMToken.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "FungibleToken"

import "EVM"

/// Contract defining cross-VM Fungible Token Vault interface
///
access(all) contract CrossVMToken {

/// Interface for a Fungible Token Vault with a corresponding ERC20 contract on EVM
access(all) resource interface EVMTokenInfo {
/// Gets the ERC20 name value
access(all) view fun getName(): String
/// Gets the ERC20 symbol value
access(all) view fun getSymbol(): String
/// Gets the ERC20 decimals value
access(all) view fun getDecimals(): UInt8
/// Get the EVM contract address of the corresponding ERC20 contract address
access(all) view fun getEVMContractAddress(): EVM.EVMAddress
}
}
Loading

0 comments on commit 9b6dc21

Please sign in to comment.