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

Enable evm #71

Merged
merged 31 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d940912
refactor contracts for Cadence 1.0
sisyphusSmiling Feb 13, 2024
ae508ed
add EVM contract
sisyphusSmiling Feb 13, 2024
42be8c3
update FUSD for emulator FungibleToken conformance
sisyphusSmiling Feb 13, 2024
12fb1c7
add FlowPassthrough.sol contract
sisyphusSmiling Feb 14, 2024
fa585cf
add FlowEVMPassthrough.cdc contract & update flow.json
sisyphusSmiling Feb 14, 2024
6b58373
add evm scripts
sisyphusSmiling Feb 14, 2024
35ac424
add evm transactions
sisyphusSmiling Feb 14, 2024
f2ac15a
update all transactions for Cadence 1.0 compatibility
sisyphusSmiling Feb 14, 2024
67a13d8
update flow.json with crescendo aliases
sisyphusSmiling Feb 14, 2024
5901ff1
update FlowEVMPassthrough pre-condition syntax
sisyphusSmiling Feb 14, 2024
12fa01b
add CryptoUtils contract & name in flow.json & env.example
sisyphusSmiling Feb 14, 2024
9a9aed5
add env vars to publicConfig.ts
sisyphusSmiling Feb 14, 2024
7ccb0cb
update lib cadence to 1.0
sisyphusSmiling Feb 14, 2024
8cfa6b0
fix fund.ts Cadence
sisyphusSmiling Feb 14, 2024
7e00886
update flow.json
sisyphusSmiling Feb 14, 2024
fd30f59
add contract alias info to fclConfig.ts
sisyphusSmiling Feb 14, 2024
1464d87
fix flow.json
sisyphusSmiling Feb 14, 2024
1210192
rename coa creation transaction
sisyphusSmiling Feb 14, 2024
28296e1
fix account.ts Cadence
sisyphusSmiling Feb 14, 2024
c4779d2
update evm transactions
sisyphusSmiling Feb 14, 2024
10b0256
update dev-deploy-contracts command
sisyphusSmiling Feb 14, 2024
24c4f82
remove passthrough Cadence & solidity contracts
sisyphusSmiling Feb 15, 2024
6450b22
add EVM funding & COA transactions
sisyphusSmiling Feb 15, 2024
352fec4
remove CryptoUtils
sisyphusSmiling Feb 15, 2024
a037f9e
update npm run dev-deploy-contracts command
sisyphusSmiling Feb 15, 2024
399f0d5
update ts formatting
sisyphusSmiling Feb 15, 2024
d94652a
update ts formatting & add ci EVM contract env alias
sisyphusSmiling Feb 15, 2024
70b5e50
add contractEVM to PublicConfig
sisyphusSmiling Feb 15, 2024
4409076
Merge branch 'main' into chasefleming/update-evm-branch
chasefleming Feb 20, 2024
b08a0ab
Merge pull request #73 from onflow/chasefleming/update-evm-branch
chasefleming Feb 20, 2024
df81478
update mint_and_fund_evm_address transaction
sisyphusSmiling Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
NEXT_PUBLIC_CONTRACT_FUNGIBLE_TOKEN: "0xee82856bf20e2aa6"
NEXT_PUBLIC_CONTRACT_FLOW_TOKEN: "0x0ae53cb6e3f42a79"
NEXT_PUBLIC_CONTRACT_FUSD: "0xf8d6e0586b0a20c7"
NEXT_PUBLIC_CONTRACT_EVM: "0xf8d6e0586b0a20c7"
NEXT_PUBLIC_NETWORK: "testnet"

strategy:
Expand Down
44 changes: 44 additions & 0 deletions cadence/contracts/Burner.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// Burner is a contract that can facilitate the destruction of any resource on flow.
///
/// Contributors
/// - Austin Kline - https://twitter.com/austin_flowty
/// - Deniz Edincik - https://twitter.com/bluesign
/// - Bastian Müller - https://twitter.com/turbolent
access(all) contract Burner {
/// When Crescendo (Cadence 1.0) is released, custom destructors will be removed from cadece.
/// Burnable is an interface meant to replace this lost feature, allowing anyone to add a callback
/// method to ensure they do not destroy something which is not meant to be,
/// or to add logic based on destruction such as tracking the supply of a FT Collection
///
/// NOTE: The only way to see benefit from this interface
/// is to always use the burn method in this contract. Anyone who owns a resource can always elect **not**
/// to destroy a resource this way
access(all) resource interface Burnable {
access(contract) fun burnCallback()
}

/// burn is a global method which will destroy any resource it is given.
/// If the provided resource implements the Burnable interface,
/// it will call the burnCallback method and then destroy afterwards.
access(all) fun burn(_ r: @AnyResource) {
if let s <- r as? @{Burnable} {
s.burnCallback()
destroy s
} else if let arr <- r as? @[AnyResource] {
while arr.length > 0 {
let item <- arr.removeFirst()
self.burn(<-item)
}
destroy arr
} else if let dict <- r as? @{HashableStruct: AnyResource} {
let keys = dict.keys
while keys.length > 0 {
let item <- dict.remove(key: keys.removeFirst())!
self.burn(<-item)
}
destroy dict
} else {
destroy r
}
}
}
160 changes: 160 additions & 0 deletions cadence/contracts/EVM.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import "FlowToken"

access(all)
contract EVM {

/// EVMAddress is an EVM-compatible address
access(all)
struct EVMAddress {

/// Bytes of the address
access(all)
let bytes: [UInt8; 20]

/// Constructs a new EVM address from the given byte representation
init(bytes: [UInt8; 20]) {
self.bytes = bytes
}

/// Deposits the given vault into the EVM account with the given address
access(all)
fun deposit(from: @FlowToken.Vault) {
InternalEVM.deposit(
from: <-from,
to: self.bytes
)
}

/// Balance of the address
access(all)
fun balance(): Balance {
let balance = InternalEVM.balance(
address: self.bytes
)

return Balance(flow: balance)
}
}

access(all)
struct Balance {

/// The balance in FLOW
access(all)
let flow: UFix64

/// Constructs a new balance, given the balance in FLOW
init(flow: UFix64) {
self.flow = flow
}

// TODO:
// /// Returns the balance in terms of atto-FLOW.
// /// Atto-FLOW is the smallest denomination of FLOW inside EVM
// access(all)
// fun toAttoFlow(): UInt64
}

access(all)
resource BridgedAccount {

access(self)
let addressBytes: [UInt8; 20]

init(addressBytes: [UInt8; 20]) {
self.addressBytes = addressBytes
}

/// The EVM address of the bridged account
access(all)
fun address(): EVMAddress {
// Always create a new EVMAddress instance
return EVMAddress(bytes: self.addressBytes)
}

/// Get balance of the bridged account
access(all)
fun balance(): Balance {
return self.address().balance()
}

/// Deposits the given vault into the bridged account's balance
access(all)
fun deposit(from: @FlowToken.Vault) {
self.address().deposit(from: <-from)
}

/// Withdraws the balance from the bridged account's balance
access(all)
fun withdraw(balance: Balance): @FlowToken.Vault {
let vault <- InternalEVM.withdraw(
from: self.addressBytes,
amount: balance.flow
) as! @FlowToken.Vault
return <-vault
}

/// Deploys a contract to the EVM environment.
/// Returns the address of the newly deployed contract
access(all)
fun deploy(
code: [UInt8],
gasLimit: UInt64,
value: Balance
): EVMAddress {
let addressBytes = InternalEVM.deploy(
from: self.addressBytes,
code: code,
gasLimit: gasLimit,
value: value.flow
)
return EVMAddress(bytes: addressBytes)
}

/// Calls a function with the given data.
/// The execution is limited by the given amount of gas
access(all)
fun call(
to: EVMAddress,
data: [UInt8],
gasLimit: UInt64,
value: Balance
): [UInt8] {
return InternalEVM.call(
from: self.addressBytes,
to: to.bytes,
data: data,
gasLimit: gasLimit,
value: value.flow
)
}
}

/// Creates a new bridged account
access(all)
fun createBridgedAccount(): @BridgedAccount {
return <-create BridgedAccount(
addressBytes: InternalEVM.createBridgedAccount()
)
}

/// Runs an a RLP-encoded EVM transaction, deducts the gas fees,
/// and deposits the gas fees into the provided coinbase address.
///
/// Returns true if the transaction was successful,
/// and returns false otherwise
access(all)
fun run(tx: [UInt8], coinbase: EVMAddress) {
InternalEVM.run(tx: tx, coinbase: coinbase.bytes)
}

access(all)
fun encodeABI(_ values: [AnyStruct]): [UInt8] {
return InternalEVM.encodeABI(values)
}

access(all)
fun decodeABI(types: [Type], data: [UInt8]): [AnyStruct] {
return InternalEVM.decodeABI(types: types, data: data)
}
}
Loading
Loading