Skip to content

Commit

Permalink
feat: add bounds to percentage fee response (#360)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->

## Related Issue Or Context
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Otherwise, describe context and motivation for change herre -->

Closes: #<issue>

## How Has This Been Tested? Testing details.
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] 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:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [ ] 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 <[email protected]>
  • Loading branch information
mpetrunic authored Mar 20, 2024
1 parent 52a8006 commit 3114dad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/sdk/src/chains/EVM/fee/percentageFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,7 +27,7 @@ export const getPercentageFee = async ({
toDomainID: number;
resourceID: string;
depositData: string;
}): Promise<EvmFee> => {
}): Promise<PercentageFee> => {
const percentageFeeHandlerContract = PercentageERC20FeeHandlerEVM__factory.connect(
precentageFeeHandlerAddress,
provider,
Expand All @@ -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,
};
};
6 changes: 6 additions & 0 deletions packages/sdk/src/chains/EVM/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3114dad

Please sign in to comment.