From 47f8732115b01616fab8a98915764acc628b9d66 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:01:05 -0600 Subject: [PATCH] update bridge fee approximation in nft bridging txns --- cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc | 6 ++++-- .../bridge/nft/bridge_nft_to_any_cadence_address.cdc | 6 ++++-- .../bridge/nft/bridge_nft_to_any_evm_address.cdc | 9 ++++----- cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc | 9 ++++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc index 3e813a43..e569da73 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc @@ -64,8 +64,10 @@ transaction(nftIdentifier: String, id: UInt256) { /* --- Configure a ScopedFTProvider --- */ // - // Calculate the bridge fee - bridging from EVM consumes no storage, so flat fee - let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0) + // Set a cap on the withdrawable bridge fee + var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( + bytes: 200_000 // 200 kB as upper bound on movable storage used in a single transaction + ) // Issue and store bridge-dedicated Provider Capability in storage if necessary if signer.storage.type(at: FlowEVMBridgeConfig.providerCapabilityStoragePath) == nil { let providerCap = signer.capabilities.storage.issue( diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc index 2c3f3aa3..6513cffb 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc @@ -67,8 +67,10 @@ transaction(nftIdentifier: String, id: UInt256, recipient: Address) { /* --- Configure a ScopedFTProvider --- */ // - // Calculate the bridge fee - bridging from EVM consumes no storage, so flat fee - let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0) + // Set a cap on the withdrawable bridge fee + var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( + bytes: 200_000 // 200 kB as upper bound on movable storage used in a single transaction + ) // Issue and store bridge-dedicated Provider Capability in storage if necessary if signer.storage.type(at: FlowEVMBridgeConfig.providerCapabilityStoragePath) == nil { let providerCap = signer.capabilities.storage.issue( diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc index 2a33a33e..80182974 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc @@ -52,15 +52,14 @@ transaction(nftIdentifier: String, id: UInt64, recipient: String) { ) ?? panic("Could not access signer's NFT Collection") // Withdraw the requested NFT & calculate the approximate bridge fee based on NFT storage usage - let currentStorageUsage = signer.storage.used self.nft <- collection.withdraw(withdrawID: id) - let withdrawnStorageUsage = signer.storage.used var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( - bytes: currentStorageUsage - withdrawnStorageUsage - ) * 1.10 + bytes: 200_000 // 200 kB as upper bound on movable storage used in a single transaction + ) // Determine if the NFT requires onboarding - this impacts the fee required self.requiresOnboarding = FlowEVMBridge.typeRequiresOnboarding(self.nft.getType()) ?? panic("Bridge does not support this asset type") + // Add the onboarding fee if onboarding is necessary if self.requiresOnboarding { approxFee = approxFee + FlowEVMBridgeConfig.onboardFee } @@ -100,7 +99,7 @@ transaction(nftIdentifier: String, id: UInt64, recipient: String) { feeProvider: &self.scopedProvider as auth(FungibleToken.Withdraw) &{FungibleToken.Provider} ) } - // Execute the bridge transaction + // Execute the bridge to EVM let recipientEVMAddress = EVM.addressFromString(recipient) FlowEVMBridge.bridgeNFTToEVM( token: <-self.nft, diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc index 82986f80..9a987a3d 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc @@ -58,16 +58,15 @@ transaction(nftIdentifier: String, id: UInt64) { from: collectionData.storagePath ) ?? panic("Could not access signer's NFT Collection") - // Withdraw the requested NFT & calculate the approximate bridge fee based on NFT storage usage - let currentStorageUsage = signer.storage.used + // Withdraw the requested NFT & set a cap on the withdrawable bridge fee self.nft <- collection.withdraw(withdrawID: id) - let withdrawnStorageUsage = signer.storage.used var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( - bytes: currentStorageUsage - withdrawnStorageUsage - ) * 1.10 + bytes: 200_000 // 200 kB as upper bound on movable storage used in a single transaction + ) // Determine if the NFT requires onboarding - this impacts the fee required self.requiresOnboarding = FlowEVMBridge.typeRequiresOnboarding(self.nft.getType()) ?? panic("Bridge does not support this asset type") + // Add the onboarding fee if onboarding is necessary if self.requiresOnboarding { approxFee = approxFee + FlowEVMBridgeConfig.onboardFee }