DeploySEALED
□%▒▓○□^^╱░█▓□!▪#~^*▫◇○?■*▒&$$@█*~~$╳@○&@█○!░@╱░$▓▒▫█*╳?╲^◆█□╳&~&
Transaction ID
Execution Fee
0.00000999 FLOWTransaction Summary
DeployContract deployment
Contract deployment
Script Arguments
0nameString
BridgeConfigV2
1codeString
import EVM from 0xe467b9dd11fa00df
import FlowToken from 0x1654653399040a61
import VaultCore from 0x79f5b5b0f95a160b
/// BridgeConfigV2 - Complete bridge solution with public interface
access(all) contract BridgeConfigV2 {
// ====================================================================
// PATHS
// ====================================================================
access(all) let BridgeStoragePath: StoragePath
access(all) let BridgePublicPath: PublicPath
access(all) let AdminStoragePath: StoragePath
// ====================================================================
// STATE
// ====================================================================
access(self) var evmVaultAddress: EVM.EVMAddress?
access(self) var totalBridgedToEVM: UFix64
access(self) var totalBridgedFromEVM: UFix64
// ====================================================================
// EVENTS
// ====================================================================
access(all) event BridgeCOACreated(coaAddress: String)
access(all) event UserBridgedToEVM(user: Address, amount: UFix64, evmRecipient: String)
access(all) event ReceivedFromEVM(user: Address, amount: UFix64)
access(all) event EVMVaultAddressSet(address: String)
// ====================================================================
// PUBLIC INTERFACE
// ====================================================================
access(all) resource interface BridgePublic {
access(all) fun getCOAAddress(): String?
access(all) fun bridgeUserFunds(
user: Address,
amount: UFix64,
evmRecipient: String
)
}
// ====================================================================
// BRIDGE RESOURCE
// ====================================================================
access(all) resource Bridge: BridgePublic {
access(self) var bridgeCOA: @EVM.CadenceOwnedAccount?
init() {
self.bridgeCOA <- nil
}
access(all) fun setupCOA() {
pre {
self.bridgeCOA == nil: "COA already exists"
}
self.bridgeCOA <-! EVM.createCadenceOwnedAccount()
let coaAddress = self.bridgeCOA?.address()?.toString() ?? "unknown"
emit BridgeCOACreated(coaAddress: coaAddress)
}
access(all) fun getCOAAddress(): String? {
return self.bridgeCOA?.address()?.toString()
}
/// Public function users can call to bridge their funds
access(all) fun bridgeUserFunds(
user: Address,
amount: UFix64,
evmRecipient: String
) {
pre {
self.bridgeCOA != nil: "COA not set up"
BridgeConfigV2.evmVaultAddress != nil: "EVM vault not set"
}
// Get vault reference
let vaultOwner = getAccount(0x79f5b5b0f95a160b)
let vaultCap = vaultOwner.capabilities.get<&VaultCore.Vault>(VaultCore.VaultPublicPath)
let vaultRef = vaultCap.borrow() ?? panic("Could not borrow vault")
// Withdraw from VaultCore
let flowVault <- vaultRef.withdrawForEVMBridge(
assetType: VaultCore.AssetType.flow,
amount: amount
) as! @FlowToken.Vault
// Deposit to COA
let coaRef = (&self.bridgeCOA as auth(EVM.Call) &EVM.CadenceOwnedAccount?)!
coaRef.deposit(from: <-flowVault)
// Call EVM vault
let calldata = self.encodeDepositFromCadence(
userAddress: user.toString(),
amount: amount
)
let attoflowAmount = amount * 100000000.0
let attoflowUInt = UInt(attoflowAmount) * 10000000000
let result = coaRef.call(
to: BridgeConfigV2.evmVaultAddress!,
data: calldata,
gasLimit: 500000,
value: EVM.Balance(attoflow: attoflowUInt)
)
assert(result.status == EVM.Status.successful,
message: "Bridge failed")
BridgeConfigV2.totalBridgedToEVM = BridgeConfigV2.totalBridgedToEVM + amount
emit UserBridgedToEVM(
user: user,
amount: amount,
evmRecipient: evmRecipient
)
}
access(all) fun receiveFromEVM(
from: @FlowToken.Vault,
user: Address
) {
let amount = from.balance
// Get vault reference
let vaultOwner = getAccount(0x79f5b5b0f95a160b)
let vaultCap = vaultOwner.capabilities.get<&VaultCore.Vault>(VaultCore.VaultPublicPath)
let vaultRef = vaultCap.borrow() ?? panic("Could not borrow vault")
vaultRef.depositFromEVMBridge(from: <-from)
BridgeConfigV2.totalBridgedFromEVM = BridgeConfigV2.totalBridgedFromEVM + amount
emit ReceivedFromEVM(user: user, amount: amount)
}
access(self) fun encodeDepositFromCadence(
userAddress: String,
amount: UFix64
): [UInt8] {
// TODO: Implement proper ABI encoding in production
// For now, placeholder selector
return [0x12, 0x34, 0x56, 0x78]
}
}
// ====================================================================
// ADMIN RESOURCE
// ====================================================================
access(all) resource Admin {
access(all) fun setEVMVaultAddress(address: String) {
BridgeConfigV2.evmVaultAddress = EVM.addressFromString(address)
emit EVMVaultAddressSet(address: address)
}
}
// ====================================================================
// PUBLIC FUNCTIONS
// ====================================================================
access(all) fun createBridge(): @Bridge {
return <- create Bridge()
}
access(all) fun getEVMVaultAddress(): String? {
return BridgeConfigV2.evmVaultAddress?.toString()
}
access(all) fun getBridgeMetrics(): {String: UFix64} {
return {
"totalBridgedToEVM": self.totalBridgedToEVM,
"totalBridgedFromEVM": self.totalBridgedFromEVM
}
}
// ====================================================================
// INIT
// ====================================================================
init() {
self.BridgeStoragePath = /storage/VaultCoreBridgeV2
self.BridgePublicPath = /public/VaultCoreBridgeV2
self.AdminStoragePath = /storage/BridgeConfigV2Admin
self.evmVaultAddress = nil
self.totalBridgedToEVM = 0.0
self.totalBridgedFromEVM = 0.0
self.account.storage.save(<-create Admin(), to: self.AdminStoragePath)
}
}
Cadence Script
1transaction(name: String, code: String ) {
2 prepare(signer: auth(AddContract) &Account) {
3 signer.contracts.add(name: name, code: code.utf8 )
4 }
5 }