Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8fd8ea5

Browse files
committed
calculate fee via fee router
1 parent 0c76c49 commit 8fd8ea5

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

contracts/adapters/nativeTokens/NativeTokenAdapter.sol

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.11;
33

44
import "@openzeppelin/contracts/access/AccessControl.sol";
55
import "../../interfaces/IBridge.sol";
6-
import "../../interfaces/IBasicFeeHandler.sol";
6+
import "../../interfaces/IFeeHandler.sol";
77

88

99
contract NativeTokenAdapter is AccessControl {
@@ -24,16 +24,24 @@ contract NativeTokenAdapter is AccessControl {
2424
_;
2525
}
2626

27-
constructor(address bridge, IBasicFeeHandler feeHandler, bytes32 resourceID) {
27+
constructor(address bridge, bytes32 resourceID) {
2828
_bridge = IBridge(bridge);
2929
_resourceID = resourceID;
30-
_feeHandler = feeHandler;
3130
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
3231
}
3332

3433
function deposit(uint8 destinationDomainID, string calldata recipientAddress) external payable {
3534
if (msg.value <= 0) revert InsufficientMsgValueAmount(msg.value);
36-
uint256 fee = _feeHandler._domainResourceIDToFee(destinationDomainID, _resourceID);
35+
address feeHandlerRouter = _bridge._feeHandler();
36+
(uint256 fee, ) = IFeeHandler(feeHandlerRouter).calculateFee(
37+
address(this),
38+
_bridge._domainID(),
39+
destinationDomainID,
40+
_resourceID,
41+
"", // depositData - not parsed
42+
"" // feeData - not parsed
43+
);
44+
3745
if (msg.value < fee) revert MsgValueLowerThanFee(msg.value);
3846
uint256 transferAmount = msg.value - fee;
3947

contracts/interfaces/IBridge.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ interface IBridge {
1313
*/
1414
function _domainID() external returns (uint8);
1515

16+
/**
17+
@notice Exposing getter for {_feeHandler} instead of forcing the use of call.
18+
@return address The {_feeHandler} that is currently set for the Bridge contract.
19+
*/
20+
function _feeHandler() external returns (address);
21+
1622
/**
1723
@notice Exposing getter for {_resourceIDToHandlerAddress}.
1824
@param resourceID ResourceID to be used when making deposits.

test/adapters/native/collectFee.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ contract("Bridge - [collect fee - native token]", async (accounts) => {
4848
);
4949
NativeTokenAdapterInstance = await NativeTokenAdapterContract.new(
5050
BridgeInstance.address,
51-
BasicFeeHandlerInstance.address,
5251
resourceID
5352
);
5453
NativeTokenHandlerInstance = await NativeTokenHandlerContract.new(

test/adapters/native/decimalConversion.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ contract("Bridge - [decimal conversion - native token]", async (accounts) => {
6161
);
6262
NativeTokenAdapterInstance = await NativeTokenAdapterContract.new(
6363
BridgeInstance.address,
64-
BasicFeeHandlerInstance.address,
6564
resourceID
6665
);
6766
NativeTokenHandlerInstance = await NativeTokenHandlerContract.new(

test/adapters/native/deposit.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ contract("Bridge - [deposit - native token]", async (accounts) => {
4949
);
5050
NativeTokenAdapterInstance = await NativeTokenAdapterContract.new(
5151
BridgeInstance.address,
52-
BasicFeeHandlerInstance.address,
5352
resourceID
5453
);
5554
NativeTokenHandlerInstance = await NativeTokenHandlerContract.new(
@@ -136,13 +135,12 @@ contract("Bridge - [deposit - native token]", async (accounts) => {
136135
});
137136
});
138137

139-
it("Deposit destination domain can not be current bridge domain", async () => {
140-
await Helpers.expectToRevertWithCustomError(
138+
it("Should revert if destination domain is current bridge domain", async () => {
139+
await TruffleAssert.reverts(
141140
NativeTokenAdapterInstance.deposit(originDomainID, btcRecipientAddress, {
142141
from: depositorAddress,
143142
value: depositAmount
144-
}),
145-
"DepositToCurrentDomain()"
143+
})
146144
);
147145
});
148146

@@ -160,12 +158,11 @@ contract("Bridge - [deposit - native token]", async (accounts) => {
160158
emptySetResourceData
161159
);
162160

163-
await Helpers.expectToRevertWithCustomError(
161+
await TruffleAssert.reverts(
164162
NativeTokenAdapterInstance.deposit(destinationDomainID, btcRecipientAddress, {
165163
from: depositorAddress,
166164
value: depositAmount
167-
}),
168-
"InvalidSender(address)"
165+
})
169166
);
170167
});
171168
});

test/adapters/native/distributeFee.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ contract("Native token adapter - [distributeFee]", async (accounts) => {
6262

6363
NativeTokenAdapterInstance = await NativeTokenAdapterContract.new(
6464
BridgeInstance.address,
65-
BasicFeeHandlerInstance.address,
6665
resourceID
6766
);
6867

test/adapters/native/executeProposal.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ contract("Bridge - [execute proposal - native token]", async (accounts) => {
5454
);
5555
NativeTokenAdapterInstance = await NativeTokenAdapterContract.new(
5656
BridgeInstance.address,
57-
BasicFeeHandlerInstance.address,
5857
resourceID
5958
);
6059
NativeTokenHandlerInstance = await NativeTokenHandlerContract.new(

0 commit comments

Comments
 (0)