From b8f3e082dec1413cf7f8e92113349f056547d267 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:00:16 -0800 Subject: [PATCH] fix dynamic vm transfer sourcing from evm sending to cadence --- .../transactions/flow-token/dynamic_vm_transfer.cdc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cadence/transactions/flow-token/dynamic_vm_transfer.cdc b/cadence/transactions/flow-token/dynamic_vm_transfer.cdc index 4ef42f72..f1771e46 100644 --- a/cadence/transactions/flow-token/dynamic_vm_transfer.cdc +++ b/cadence/transactions/flow-token/dynamic_vm_transfer.cdc @@ -1,3 +1,4 @@ +import "FlowStorageFees" import "FungibleToken" import "FlowToken" @@ -18,7 +19,7 @@ transaction(addressString: String, amount: UFix64) { let sentVault: @FlowToken.Vault let evmRecipient: EVM.EVMAddress? var receiver: &{FungibleToken.Receiver}? - + prepare(signer: auth(BorrowValue, SaveValue) &Account) { // Reference signer's COA if one exists let coa = signer.storage.borrow(from: /storage/evm) @@ -26,8 +27,9 @@ transaction(addressString: String, amount: UFix64) { // Reference signer's FlowToken Vault let sourceVault = signer.storage.borrow(from: /storage/flowTokenVault) ?? panic("Could not borrow signer's FlowToken.Vault") - let cadenceBalance = sourceVault.balance - + // Ensure we don't withdraw more than required for storage + let cadenceBalance = FlowStorageFees.defaultTokenAvailableBalance(signer.address) + // Define optional recipients for both VMs self.receiver = nil let cadenceRecipient = Address.fromString(addressString) @@ -56,7 +58,7 @@ transaction(addressString: String, amount: UFix64) { if amount > self.sentVault.balance { let difference = amount - cadenceBalance // Revert if the signer doesn't have an EVM account or EVM balance is insufficient - if coa == nil || difference < coa!.balance().inFLOW() { + if coa == nil || difference > coa!.balance().inFLOW() { panic("Insufficient balance across Flow and EVM accounts") } @@ -101,4 +103,4 @@ transaction(addressString: String, amount: UFix64) { self.evmRecipient!.deposit(from: <-self.sentVault) } } -} +} \ No newline at end of file