Skip to content

Commit

Permalink
remove CryptoUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Feb 15, 2024
1 parent 6450b22 commit 352fec4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 67 deletions.
34 changes: 0 additions & 34 deletions cadence/contracts/CryptoUtils.cdc

This file was deleted.

8 changes: 4 additions & 4 deletions cadence/transactions/evm/create_coa_and_fund.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import "FlowToken"

import "EVM"

/// Creates a COA and saves it in the signer's Flow account & passing the given value of Flow into FlowEVM
/// Creates a COA and saves it in the signer's Flow account (if one doesn't already exist at the expected path) and
/// transfers the given value of Flow into FlowEVM, funding with the signer's Flow Vault.
///
transaction(amount: UFix64) {
let sentVault: @FlowToken.Vault
Expand All @@ -15,12 +16,11 @@ transaction(amount: UFix64) {
) ?? 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 {
if signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createBridgedAccount(), to: /storage/evm)
}
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/EVM)
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the signer's COA!")

}

execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import "FlowToken"

import "EVM"

import "CryptoUtils"

/// Creates a Flow account with a COA and saves it in the created account. The provided amount is then deposited into
/// the Flow account at the ratio provided and the remaining amount is deposited into the newly created COA.
/// Creates a Flow account with a COA and saves it in the created account. The provided amount is then minted,
/// deposited into the Flow account at the specified ratio and the remaining amount is deposited into the newly
/// created COA.
///
transaction(
publicKey: String,
Expand All @@ -22,10 +21,12 @@ transaction(
prepare(signer: auth(Storage) &Account) {
self.newAccount = Account(payer: signer)

let signatureAlgorithm = CryptoUtils.getSigAlgo(fromRawValue: sigAlgorithm)
let signatureAlgorithm = SignatureAlgorithm(sigAlgorithm)
?? panic("Invalid SignatureAlgorithm")
let hashAlgorithm = CryptoUtils.getHashAlgo(fromRawValue: sigAlgorithm)
log(signatureAlgorithm)
let hashAlgorithm = HashAlgorithm(hashAlgorithm)
?? panic("Invalid HashAlgorithm")
log(hashAlgorithm)

let key = PublicKey(
publicKey: publicKey.decodeHex(),
Expand Down
11 changes: 4 additions & 7 deletions cadence/transactions/evm/mint_and_fund_evm_address.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ transaction(to: EVM.EVMAddress, amount: UFix64, gasLimit: UInt64) {
let tokenReceiver: &{FungibleToken.Receiver}
let coa: &EVM.BridgedAccount

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

self.tokenReceiver = signer.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
?? panic("Unable to borrow receiver reference")
if signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm) == nil {
signer.storage.save(<-EVM.createBridgedAccount(), to: /storage/evm)
}
self.coa = signer.storage.borrow<&EVM.BridgedAccount>(from: /storage/evm)
?? panic("Could not borrow reference to the signer's COA!")
}
Expand All @@ -26,12 +29,6 @@ transaction(to: EVM.EVMAddress, amount: UFix64, gasLimit: UInt64) {
let mintedVault <- minter.mintTokens(amount: amount)
destroy minter

// TODO: REMOVE
let bytes = toStr.decodeHex()
let to = EVM.EVMAddress(bytes: [
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9],
bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15], bytes[16], bytes[17], bytes[18], bytes[19]
])
self.coa.deposit(from: <-mintedVault)
self.coa.call(
to: to,
Expand Down
1 change: 0 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ NEXT_PUBLIC_CONTRACT_FUNGIBLE_TOKEN=0xee82856bf20e2aa6
NEXT_PUBLIC_CONTRACT_FLOW_TOKEN=0x0ae53cb6e3f42a79
NEXT_PUBLIC_CONTRACT_FUSD=0xf8d6e0586b0a20c7
NEXT_PUBLIC_CONTRACT_EVM=0xf8d6e0586b0a20c7
NEXT_PUBLIC_CONTRACT_CRYPTO_UTILS=0xf8d6e0586b0a20c7
NEXT_PUBLIC_GA_MEASUREMENT_ID=

SIGNER_HASH_ALGO=SHA2_256
Expand Down
9 changes: 1 addition & 8 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"emulator": "ee82856bf20e2aa6"
}
},
"CryptoUtils": {
"source": "./cadence/contracts/CryptoUtils.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"EVM": {
"source": "./cadence/contracts/EVM.cdc",
"aliases": {
Expand Down Expand Up @@ -108,8 +102,7 @@
"FungibleTokenMetadataViews",
"Burner",
"FUSD",
"ViewResolver",
"CryptoUtils"
"ViewResolver"
]
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/fclConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ config()
.put("0xFLOWTOKENADDRESS", publicConfig.contractFlowToken)
.put("0xFUSDADDRESS", publicConfig.contractFUSD)
.put("0xEVMADDRESS", publicConfig.contractEVM)
.put("0xCRYPTOUTILSADDRESS", publicConfig.contractCryptoUtils)
5 changes: 2 additions & 3 deletions lib/flow/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { sendTransaction } from "./send"
const accountCreatedEventType = "flow.AccountCreated"

const txCreateAccount = `
import CryptoUtils from ${publicConfig.contractFlowToken}
import FlowToken from ${publicConfig.contractFlowToken}
import FungibleToken from ${publicConfig.contractFungibleToken}
Expand All @@ -18,9 +17,9 @@ transaction(publicKey: String, flowTokenAmount: UFix64, sigAlgorithm: UInt8, has
prepare(signer: auth(BorrowValue) &Account) {
let account = Account(payer: signer)
let signatureAlgorithm = CryptoUtils.getSigAlgo(fromRawValue: sigAlgorithm)
let signatureAlgorithm = SignatureAlgorithm(sigAlgorithm)
?? panic("Invalid SignatureAlgorithm")
let hashAlgorithm = CryptoUtils.getHashAlgo(fromRawValue: sigAlgorithm)
let hashAlgorithm = HashAlgorithm(hashAlgorithm)
?? panic("Invalid HashAlgorithm")
let key = PublicKey(
Expand Down
3 changes: 0 additions & 3 deletions lib/publicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ if (!contractFUSD) throw "Missing NEXT_PUBLIC_CONTRACT_FUSD"
const contractEVM = process.env.NEXT_PUBLIC_CONTRACT_EVM
if (!contractEVM) throw "Missing NEXT_PUBLIC_CONTRACT_EVM"

const contractCryptoUtils = process.env.NEXT_PUBLIC_CONTRACT_CRYPTO_UTILS
if (!contractCryptoUtils) throw "Missing NEXT_PUBLIC_CONTRACT_CRYPTO_UTILS"

const walletDiscovery = process.env.NEXT_PUBLIC_WALLET_DISCOVERY
// TODO: Integrate FCL wallets
// if (!walletDiscovery) throw "Missing NEXT_PUBLIC_WALLET_DISCOVERY"
Expand Down

0 comments on commit 352fec4

Please sign in to comment.