Skip to content

Commit

Permalink
chore: extend IFeeHandler with feeHandlerType getter
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Jun 6, 2024
1 parent cfc09d8 commit f2f51a2
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 9 deletions.
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

0 comments on commit f2f51a2

Please sign in to comment.