diff --git a/packages/sdk/src/chains/EVM/assetTransfer.ts b/packages/sdk/src/chains/EVM/assetTransfer.ts index cc73c77f6..8f05f1799 100644 --- a/packages/sdk/src/chains/EVM/assetTransfer.ts +++ b/packages/sdk/src/chains/EVM/assetTransfer.ts @@ -262,20 +262,15 @@ export class EVMAssetTransfer extends BaseAssetTransfer { handlerAddress: string, ): Promise> { const approvals: Array = []; - const transferAmount = BigNumber.from(transfer.details.amount); if ( - fee.type == FeeHandlerType.PERCENTAGE && - (await getERC20Allowance(transfer.sender, erc20, fee.handlerAddress)).lt( - fee.fee.add(transferAmount), - ) - ) { - approvals.push( - await approve(fee.fee.add(transferAmount).toString(), erc20, fee.handlerAddress), - ); - } else if ( - fee.type == FeeHandlerType.BASIC && - (await getERC20Allowance(transfer.sender, erc20, handlerAddress)).lt(transferAmount) + fee.type == FeeHandlerType.DYNAMIC && + (await getERC20Allowance(transfer.sender, erc20, fee.handlerAddress)).lt(fee.fee) ) { + approvals.push(await approve(fee.fee.toString(), erc20, fee.handlerAddress)); + } + + const transferAmount = BigNumber.from(transfer.details.amount); + if ((await getERC20Allowance(transfer.sender, erc20, handlerAddress)).lt(transferAmount)) { approvals.push(await approve(transferAmount.toString(), erc20, handlerAddress)); } diff --git a/packages/sdk/src/chains/EVM/utils/depositFns.ts b/packages/sdk/src/chains/EVM/utils/depositFns.ts index 0053c84db..a97d60858 100644 --- a/packages/sdk/src/chains/EVM/utils/depositFns.ts +++ b/packages/sdk/src/chains/EVM/utils/depositFns.ts @@ -2,7 +2,6 @@ import { BigNumber, ContractReceipt, PopulatedTransaction, ethers } from 'ethers import { Bridge } from '@buildwithsygma/sygma-contracts'; import { DepositEvent } from '@buildwithsygma/sygma-contracts/dist/ethers/Bridge.js'; -import { FeeHandlerType } from '../../../types'; import { createERCDepositData, createPermissionlessGenericDepositData } from '../helpers.js'; import { Erc20TransferParamsType, Erc721TransferParamsType, EvmFee } from '../types/index.js'; @@ -134,7 +133,7 @@ export const executeDeposit = async ( overrides?: ethers.PayableOverrides, ): Promise => { const transactionSettings = { - value: feeData.type == FeeHandlerType.PERCENTAGE ? 0 : feeData.fee, + value: feeData.fee, gasLimit: ASSET_TRANSFER_GAS_LIMIT, }; diff --git a/packages/sdk/test/chains/EVM/assetTransfer.test.ts b/packages/sdk/test/chains/EVM/assetTransfer.test.ts index 992a135c2..b7e74cdae 100644 --- a/packages/sdk/test/chains/EVM/assetTransfer.test.ts +++ b/packages/sdk/test/chains/EVM/assetTransfer.test.ts @@ -214,7 +214,7 @@ describe('EVM asset transfer', () => { const fee = { fee: BigNumber.from('100'), - type: FeeHandlerType.PERCENTAGE, + type: FeeHandlerType.DYNAMIC, handlerAddress: '0xe495c86962DcA7208ECcF2020A273395AcE8da3e', }; const approvals = await assetTransfer.buildApprovals(transfer, fee); @@ -222,19 +222,19 @@ describe('EVM asset transfer', () => { expect(approvals.length).toBe(1); }); - it('Should return 1 approval txs if ERC20 token not approved and percentage fee used', async function () { + it('Should return 2 approval txs if ERC20 token not approved and dynamic fee used', async function () { resourceHandlerFunction.mockResolvedValue('0x03896BaeA3A8CD98E46C576AF6Ceaffb69a51AFB'); getAllowanceMock.mockResolvedValue(BigNumber.from('0')); approveMock.mockResolvedValue({}); const fee = { fee: BigNumber.from('100'), - type: FeeHandlerType.PERCENTAGE, + type: FeeHandlerType.DYNAMIC, handlerAddress: '0xe495c86962DcA7208ECcF2020A273395AcE8da3e', }; const approvals = await assetTransfer.buildApprovals(transfer, fee); - expect(approvals.length).toBe(1); + expect(approvals.length).toBe(2); }); it('Should return empty array if ERC721 token already approved', async function () {