Skip to content

Commit

Permalink
feat: add additional estimateAdditionalCost view function
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Jun 6, 2024
1 parent f4a4458 commit 69a7905
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/apps/mock/IncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ contract IncentivizedMockEscrow is IncentivizedMessageEscrow, Ownable2Step {
amount = costOfMessages;
}

function estimateAdditionalCost(bytes32 /* destinationChainIdentifier */) external view returns(address asset, uint256 amount) {
asset = address(0);
amount = costOfMessages;
}

function collectPayments() external {
unchecked {
payable(owner()).transfer(accumulator - 1);
Expand Down
5 changes: 5 additions & 0 deletions src/apps/mock/OnRecvIncentivizedMockEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ contract OnRecvIncentivizedMockEscrow is IncentivizedMessageEscrow {
amount = 0;
}

function estimateAdditionalCost(bytes32 /* destinationChainIdentifier */) external pure returns(address asset, uint256 amount) {
asset = address(0);
amount = 0;
}

function _proofValidPeriod(bytes32 /* destinationIdentifier */) override internal pure returns(uint64) {
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions src/apps/polymer/APolymerEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ abstract contract APolymerEscrow is IncentivizedMessageEscrow {
amount = 0;
}

function estimateAdditionalCost(bytes32 /* destinationChainIdentifier */) external pure returns(address asset, uint256 amount) {
asset = address(0);
amount = 0;
}

function _uniqueSourceIdentifier() internal view override returns (bytes32 sourceIdentifier) {
return sourceIdentifier = bytes32(block.chainid);
}
Expand Down
5 changes: 5 additions & 0 deletions src/apps/wormhole/IncentivizedWormholeEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifi
amount = WORMHOLE.messageFee();
}

function estimateAdditionalCost(bytes32 /* destinationChainIdentifier */) external view returns(address asset, uint256 amount) {
asset = address(0);
amount = WORMHOLE.messageFee();
}

/** @notice Wormhole proofs are valid until the guardian set is changed. The new guradian set may sign a new VAA */
function _proofValidPeriod(bytes32 /* destinationIdentifier */) override internal pure returns(uint64) {
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/IIncentivizedMessageEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ interface IIncentivizedMessageEscrow is IMessageEscrowStructs, IMessageEscrowErr
* @return amount The number of assets to pay.
*/
function estimateAdditionalCost() external view returns(address asset, uint256 amount);

/**
* @notice Estimates the additional cost to the messaging router to validate the message
* @param destinationChainIdentifier Destination chain. Some messaging protocols have chain based costs.
* @return asset The asset the token is in. If native token, returns address(0);
* @return amount The number of assets to pay.
*/
function estimateAdditionalCost(bytes32 destinationChainIdentifier) external view returns(address asset, uint256 amount);

function timeoutMessage(
bytes32 sourceIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract CallReentryTest is TestCommon, ICrossChainReceiver {
messageIdentifier,
_DESTINATION_ADDRESS_APPLICATION,
feeRecipient,
uint48(0xfcb6), // Gas used
uint48(0xfccc), // Gas used
uint64(1),
uint8(1)
)
Expand Down
2 changes: 1 addition & 1 deletion test/layerzero/TestLZMisc.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ contract TestLZMisc is LZCommon {
address(layerZeroEscrow),
abi.encodeCall(layerZeroEscrow.getFee, (remoteEid, address(layerZeroEscrow), 0, hex""))
);
layerZeroEscrow.estimateAdditionalCost(remoteEid);
layerZeroEscrow.estimateAdditionalCost(bytes32(uint256(remoteEid)));
}
}

0 comments on commit 69a7905

Please sign in to comment.