Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extend IFeeHandler with feeHandlerType getter #248

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contracts/handlers/FeeHandlerRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ contract FeeHandlerRouter is IFeeHandler, AccessControl {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "sender doesn't have admin role");
}

/**
@notice Getter function for fee handler type
*/
function feeHandlerType() public override pure returns (string memory) {
return "router";
}

/**
@param bridgeAddress Contract address of previously deployed Bridge.
*/
Expand Down
6 changes: 3 additions & 3 deletions contracts/handlers/fee/BasicFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ contract BasicFeeHandler is IFeeHandler, AccessControl {
}

/**
@notice Exposes getter function for fee handler type
@notice Getter function for fee handler type
*/
function feeHandlerType() virtual public pure returns (string memory) {
function feeHandlerType() public virtual override pure returns (string memory) {
return "basic";
}

Expand Down Expand Up @@ -84,7 +84,7 @@ contract BasicFeeHandler is IFeeHandler, AccessControl {
emit FeeCollected(sender, fromDomainID, destinationDomainID, resourceID, currentFee, address(0));
}

/**
/**
@notice Calculates fee for deposit.
@param sender Sender of the deposit.
@param fromDomainID ID of the source chain.
Expand Down
4 changes: 4 additions & 0 deletions contracts/handlers/fee/DynamicFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ abstract contract DynamicFeeHandler is IFeeHandler, AccessControl, ERC20Safe {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function feeHandlerType() public override pure returns (string memory) {
return "dynamic";
}

// Admin functions

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/handlers/fee/PercentageERC20FeeHandlerEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ contract PercentageERC20FeeHandlerEVM is BasicFeeHandler, ERC20Safe {
) BasicFeeHandler(bridgeAddress, feeHandlerRouterAddress) {}

/**
@notice Exposes getter function for fee handler type
@notice Getter function for fee handler type
*/
function feeHandlerType() override public pure returns (string memory) {
function feeHandlerType() public override pure returns (string memory) {
return "percentage";
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/handlers/fee/V2/DynamicFeeHandlerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ abstract contract DynamicFeeHandlerV2 is IFeeHandler, AccessControl {
}

/**
@notice Exposes getter function for fee handler type
@notice Getter function for fee handler type
*/
function feeHandlerType() virtual public pure returns (string memory) {
function feeHandlerType() public override pure returns (string memory) {
return "twap";
}

Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/IFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ interface IFeeHandler {
@return Returns the address of the token to be used for fee.
*/
function calculateFee(address sender, uint8 fromDomainID, uint8 destinationDomainID, bytes32 resourceID, bytes calldata depositData, bytes calldata feeData) external view returns(uint256, address);

/**
@notice Exposes getter function for fee handler type
*/
function feeHandlerType() pure external returns (string memory);
}
7 changes: 6 additions & 1 deletion test/handlers/fee/basic/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ contract("BasicFeeHandler - [admin]", async (accounts) => {
)
});

it("should return fee handler type", async () => {
it("[sanity] should return fee handler type from fee handler", async () => {
assert.equal(await BasicFeeHandlerInstance.feeHandlerType.call(), "basic");
});

it("[sanity] should return fee handler from fee handler router", async () => {
const feeRouterInstance = await FeeHandlerRouterContract.at(BasicFeeHandlerInstance.address)
assert.equal(await feeRouterInstance.feeHandlerType.call(), "basic");
});

it("should set fee property", async () => {
const fee = 3;
assert.equal(await BasicFeeHandlerInstance._domainResourceIDToFee(destinationDomainID, resourceID), "0");
Expand Down
9 changes: 9 additions & 0 deletions test/handlers/fee/dynamic/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ contract("DynamicFeeHandler - [admin]", async (accounts) => {
ADMIN_ROLE = await DynamicFeeHandlerInstance.DEFAULT_ADMIN_ROLE();
});

it("[sanity] should return fee handler type from fee handler", async () => {
assert.equal(await DynamicFeeHandlerInstance.feeHandlerType.call(), "dynamic");
});

it("[sanity] should return fee handler from fee handler router", async () => {
const feeRouterInstance = await FeeHandlerRouterContract.at(DynamicFeeHandlerInstance.address)
assert.equal(await feeRouterInstance.feeHandlerType.call(), "dynamic");
});

it("should set fee oracle and emit 'FeeOracleAddressSet' event", async () => {
const oracleAddress = accounts[1];
assert.equal(
Expand Down
4 changes: 4 additions & 0 deletions test/handlers/fee/handlerRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ contract("FeeHandlerRouter", async (accounts) => {
);
});

it("[sanity] should return fee handler router type", async () => {
assert.equal(await FeeHandlerRouterInstance.feeHandlerType.call(), "router");
});

it("should successfully set handler to resourceID", async () => {
const feeHandlerAddress = accounts[1];
assert.equal(
Expand Down
7 changes: 6 additions & 1 deletion test/handlers/fee/percentage/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ contract("PercentageFeeHandler - [admin]", async (accounts) => {
resourceID = Helpers.createResourceID(ERC20MintableInstance.address, originDomainID);
});

it("should return fee handler type", async () => {
it("[sanity] should return fee handler type from fee handler", async () => {
assert.equal(await PercentageFeeHandlerInstance.feeHandlerType.call(), "percentage");
});

it("[sanity] should return fee handler from fee handler router", async () => {
const feeRouterInstance = await FeeHandlerRouterContract.at(PercentageFeeHandlerInstance.address)
assert.equal(await feeRouterInstance.feeHandlerType.call(), "percentage");
});

it("should set fee property", async () => {
const fee = 60000;
assert.equal(await PercentageFeeHandlerInstance._domainResourceIDToFee(destinationDomainID, resourceID), "0");
Expand Down
Loading