From 3114dad4ec7df8ed662f55e35adaafa70cc2e6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Wed, 20 Mar 2024 11:25:29 +0100 Subject: [PATCH] feat: add bounds to percentage fee response (#360) ## Description ## Related Issue Or Context Closes: # ## How Has This Been Tested? Testing details. ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in chainbridge-docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot Signed-off-by: Marin Petrunic --- packages/sdk/src/chains/EVM/fee/percentageFee.ts | 8 +++++--- packages/sdk/src/chains/EVM/types/index.ts | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/chains/EVM/fee/percentageFee.ts b/packages/sdk/src/chains/EVM/fee/percentageFee.ts index f347153ae..f55493234 100644 --- a/packages/sdk/src/chains/EVM/fee/percentageFee.ts +++ b/packages/sdk/src/chains/EVM/fee/percentageFee.ts @@ -2,7 +2,7 @@ import { PercentageERC20FeeHandlerEVM__factory } from '@buildwithsygma/sygma-con import type { ethers } from 'ethers'; import { utils } from 'ethers'; import { FeeHandlerType } from '../../../types/index.js'; -import type { EvmFee } from '../types/index.js'; +import type { PercentageFee } from '../types/index.js'; /** * Calculates and returns the fee in native currency. @@ -27,7 +27,7 @@ export const getPercentageFee = async ({ toDomainID: number; resourceID: string; depositData: string; -}): Promise => { +}): Promise => { const percentageFeeHandlerContract = PercentageERC20FeeHandlerEVM__factory.connect( precentageFeeHandlerAddress, provider, @@ -40,12 +40,14 @@ export const getPercentageFee = async ({ depositData, utils.formatBytes32String(''), ); - + const feeBounds = await percentageFeeHandlerContract._resourceIDToFeeBounds(resourceID); const [fee] = calculatedFee; return { fee, feeData: fee.toHexString(), type: FeeHandlerType.PERCENTAGE, handlerAddress: precentageFeeHandlerAddress, + lowerBound: feeBounds.lowerBound, + upperBound: feeBounds.upperBound, }; }; diff --git a/packages/sdk/src/chains/EVM/types/index.ts b/packages/sdk/src/chains/EVM/types/index.ts index 7030c9b20..29a4405c2 100644 --- a/packages/sdk/src/chains/EVM/types/index.ts +++ b/packages/sdk/src/chains/EVM/types/index.ts @@ -10,6 +10,12 @@ export type EvmFee = { feeData?: string; }; +export type PercentageFee = EvmFee & { + type: FeeHandlerType.PERCENTAGE; + lowerBound: ethers.BigNumber; + upperBound: ethers.BigNumber; +}; + export type OracleResource = { baseEffectiveRate: string; tokenEffectiveRate: string;