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

Update EVM Cadence #79

Merged
merged 8 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
347 changes: 298 additions & 49 deletions cadence/contracts/EVM.cdc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cadence/scripts/evm/get_balance.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ access(all) fun main(address: String): UFix64 {
bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
bytes[15], bytes[16], bytes[17], bytes[18], bytes[19]
]
return EVM.EVMAddress(bytes: addressBytes).balance().flow
return EVM.EVMAddress(bytes: addressBytes).balance().inFLOW()
}
2 changes: 1 addition & 1 deletion cadence/scripts/evm/get_evm_address_string.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "EVM"
///
access(all) fun main(flowAddress: Address): String? {
let account = getAuthAccount<auth(BorrowValue) &Account>(flowAddress)
if let address = account.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)?.address() {
if let address = account.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)?.address() {
let bytes: [UInt8] = []
for byte in address.bytes {
bytes.append(byte)
Expand Down
10 changes: 5 additions & 5 deletions cadence/transactions/evm/create_coa_and_fund.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import "EVM"
///
transaction(amount: UFix64) {
let sentVault: @FlowToken.Vault
let coa: &EVM.BridgedAccount
let coa: &EVM.CadenceOwnedAccount

prepare(signer: auth(Storage) &Account) {
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdrawable) &FlowToken.Vault>(
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(
from: /storage/flowTokenVault
) ?? panic("Could not borrow reference to the owner's Vault!")

self.sentVault <- vaultRef.withdraw(amount: amount) as! @FlowToken.Vault
if signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createBridgedAccount(), to: /storage/evm)
if signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createCadenceOwnedAccount(), to: /storage/evm)
}
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)
self.coa = signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the signer's COA!")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ transaction(

self.tokenReceiver.deposit(from: <-flowVault)

let coa <- EVM.createBridgedAccount()
let coa <- EVM.createCadenceOwnedAccount()
coa.address().deposit(from: <-evmVault)

self.newAccount.storage.save(<-coa, to: StoragePath(identifier: "evm")!)
Expand Down
8 changes: 4 additions & 4 deletions cadence/transactions/evm/mint_and_fund_evm_address.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import "EVM"
transaction(to: EVM.EVMAddress, amount: UFix64, gasLimit: UInt64) {

let tokenAdmin: &FlowToken.Administrator
let coa: &EVM.BridgedAccount
let coa: auth(EVM.Call) &EVM.CadenceOwnedAccount

prepare(signer: auth(Storage) &Account) {
self.tokenAdmin = signer.storage.borrow<&FlowToken.Administrator>(from: /storage/flowTokenAdmin)
?? panic("Signer is not the token admin")

if signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createBridgedAccount(), to: /storage/evm)
if signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createCadenceOwnedAccount(), to: /storage/evm)
}
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)
self.coa = signer.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the signer's COA!")
}

Expand Down
2 changes: 1 addition & 1 deletion cadence/transactions/transfer_flow.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ transaction (amount: UFix64, to: Address) {
prepare(signer: auth(BorrowValue) &Account) {

// Get a reference to the signer's stored vault
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdrawable) &FlowToken.Vault>(from: /storage/flowTokenVault)
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")

// Withdraw tokens from the signer's stored vault
Expand Down
8 changes: 4 additions & 4 deletions lib/flow/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ import EVM from ${publicConfig.contractEVM}
transaction(to: EVM.EVMAddress, amount: UFix64, gasLimit: UInt64) {

let tokenAdmin: &FlowToken.Administrator
let coa: &EVM.BridgedAccount
let coa: auth(EVM.Call) &EVM.CadenceOwnedAccount

prepare(signer: auth(Storage) &Account) {
self.tokenAdmin = signer.storage.borrow<&FlowToken.Administrator>(from: /storage/flowTokenAdmin)
?? panic("Signer is not the token admin")

if signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createBridgedAccount(), to: /storage/evm)
if signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createCadenceOwnedAccount(), to: /storage/evm)
}
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)
self.coa = signer.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the signer's COA!")
}

Expand Down
Loading