Skip to content

Commit

Permalink
update CadenceOwnedAccount.deploy & implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Apr 19, 2024
1 parent 1721fe6 commit 16c7f58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cadence/contracts/bridge/FlowEVMBridgeUtils.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,11 @@ contract FlowEVMBridgeUtils {
}
}
// Deploy the FlowBridgeFactory.sol contract from provided bytecode and capture the deployed address
self.bridgeFactoryEVMAddress = self.borrowCOA().deploy(
let evmResult = self.borrowCOA().deploy(
code: bridgeFactoryBytecodeHex.decodeHex(),
gasLimit: 15000000,
value: EVM.Balance(attoflow: 0)
)
self.bridgeFactoryEVMAddress = evmResult.deployedContractAddress
}
}
28 changes: 18 additions & 10 deletions cadence/contracts/standards/EVM.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,31 @@ contract EVM {
access(all)
let gasUsed: UInt64

/// returns the data that is returned from
/// returns the data that is returned from
/// the evm for the call. For coa.deploy
/// calls it returns the address bytes of the
/// newly deployed contract.
/// calls it returns the code deployed to
/// the address provided in the contractAddress field.
access(all)
let data: [UInt8]

/// returns the newly deployed contract address
/// if the transaction caused such a deployment
/// otherwise the value is empty.
access(all)
let deployedContractAddress: [UInt8; 20]

init(
status: Status,
errorCode: UInt64,
gasUsed: UInt64,
data: [UInt8]
data: [UInt8],
contractAddress: [UInt8; 20]
) {
self.status = status
self.errorCode = errorCode
self.gasUsed = gasUsed
self.data = data
self.deployedContractAddress = contractAddress
}
}

Expand Down Expand Up @@ -284,20 +292,20 @@ contract EVM {
}

/// Deploys a contract to the EVM environment.
/// Returns the address of the newly deployed contract
access(Owner | Deploy)
/// Returns the result which contains address of
/// the newly deployed contract
access(all)
fun deploy(
code: [UInt8],
gasLimit: UInt64,
value: Balance
): EVMAddress {
let addressBytes = InternalEVM.deploy(
): Result {
return InternalEVM.deploy(
from: self.addressBytes,
code: code,
gasLimit: gasLimit,
value: value.attoflow
)
return EVMAddress(bytes: addressBytes)
) as! Result
}

/// Calls a function with the given data.
Expand Down
7 changes: 5 additions & 2 deletions cadence/contracts/test/EVMDeployer.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ access(all) contract EVMDeployer {
post {
self.deployedAddresses[name] != nil : "Deployment address was not stored"
}
let deploymentAddress = self.borrowCOA().deploy(

let evmResult = self.borrowCOA().deploy(
code: bytecode.decodeHex(),
gasLimit: 15_000_000,
value: EVM.Balance(attoflow: value)
)
self.deployedAddresses[name] = deploymentAddress
assert(evmResult.status == EVM.Status.successful, message: "EVM deployment failed")

self.deployedAddresses[name] = evmResult.deployedContractAddress
}

access(self) fun borrowCOA(): auth(EVM.Deploy) &EVM.CadenceOwnedAccount {
Expand Down
3 changes: 2 additions & 1 deletion cadence/transactions/evm/deploy.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ transaction(bytecode: String, gasLimit: UInt64, value: UFix64) {
let valueBalance = EVM.Balance(attoflow: 0)
valueBalance.setFLOW(flow: value)
// Finally deploy the contract
let address: EVM.EVMAddress = self.coa.deploy(
let evmResult = self.coa.deploy(
code: bytecode.decodeHex(),
gasLimit: gasLimit,
value: valueBalance
)
assert(evmResult.status == EVM.Status.successful, message: "EVM deployment failed")
}
}

0 comments on commit 16c7f58

Please sign in to comment.