Skip to content

Commit

Permalink
modify BridgeAggregationHookMetadata to only include Axelar payment data
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasDotSol committed Dec 15, 2023
1 parent 8f40524 commit c789755
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
33 changes: 4 additions & 29 deletions solidity/contracts/hooks/libs/BridgeAggregationHookMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ pragma solidity >=0.8.0;
/**
* Format of metadata:
*
* [0:2] variant
* [2:34] Axelar Payment
* [34:66] Wormhole Payment
* [66:] additional metadata
* [0:32] variant
* [32:] additional metadata
*/
library BridgeAggregationHookMetadata {
struct Metadata {
uint256 AxelarPayment;
uint256 WormholePayment;
}

uint8 private constant AXELAR_PAYMENT_OFFSET = 0;
uint8 private constant WORMHOLE_PAYMENT_OFFSET = 32;
uint8 private constant MIN_METADATA_LENGTH = 64;
uint8 private constant MIN_METADATA_LENGTH = 32;

/**
* @notice Returns the required payment for Axelar bridging.
Expand All @@ -36,24 +32,6 @@ library BridgeAggregationHookMetadata {
);
}

/**
* @notice Returns the required payment for Wormhole bridging.
* @param _metadata ABI encoded standard hook metadata.
* @return uint256 Payment amount.
*/
function wormholeGasPayment(
bytes calldata _metadata
) internal pure returns (uint256) {
if (_metadata.length < WORMHOLE_PAYMENT_OFFSET + 32) return 0;
return
uint256(
bytes32(
_metadata[WORMHOLE_PAYMENT_OFFSET:WORMHOLE_PAYMENT_OFFSET +
32]
)
);
}

/**
* @notice Returs any additional metadata.
* @param _metadata ABI encoded standard hook metadata.
Expand All @@ -69,16 +47,13 @@ library BridgeAggregationHookMetadata {
/**
* @notice Formats the specified Axelar and Wormhole payments.
* @param _axelarPayment msg.value for the message.
* @param _wormholePayment Gas limit for the message.
* @param _customMetadata Additional metadata to include.
* @return ABI encoded standard hook metadata.
*/
function formatMetadata(
uint256 _axelarPayment,
uint256 _wormholePayment,
bytes memory _customMetadata
) internal pure returns (bytes memory) {
return
abi.encodePacked(_axelarPayment, _wormholePayment, _customMetadata);
return abi.encodePacked(_axelarPayment, _customMetadata);
}
}
10 changes: 4 additions & 6 deletions solidity/test/hooks/AxelarHook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ contract AxelarHookTest is Test {
string destionationContract = "neutronContract";
address axelarGateway = address(0);
address axelarGasReceiver = address(0);
bytes gmp_call_code = abi.encodePacked(uint8(1));
error BadQuote(uint256 balance, uint256 required);

function setUp() public {
Expand All @@ -42,8 +41,7 @@ contract AxelarHookTest is Test {
destinationChain,
destionationContract,
axelarGateway,
axelarGasReceiver,
gmp_call_code
axelarGasReceiver
);
testMessage = _encodeTestMessage();
}
Expand All @@ -66,7 +64,7 @@ contract AxelarHookTest is Test {
vm.expectRevert("No Axelar Payment Received");
uint256 expectedQuote = 0;
bytes memory justRightCustomMetadata = BridgeAggregationHookMetadata
.formatMetadata(expectedQuote, 0, abi.encodePacked());
.formatMetadata(expectedQuote, abi.encodePacked());
bytes memory testMetadata = StandardHookMetadata.formatMetadata(
100,
100,
Expand All @@ -80,7 +78,7 @@ contract AxelarHookTest is Test {
function test_quoteDispatch_ReturnsSmallQuote() public {
uint256 expectedQuote = 1;
bytes memory justRightCustomMetadata = BridgeAggregationHookMetadata
.formatMetadata(expectedQuote, 0, abi.encodePacked());
.formatMetadata(expectedQuote, abi.encodePacked());
bytes memory testMetadata = StandardHookMetadata.formatMetadata(
100,
100,
Expand All @@ -96,7 +94,7 @@ contract AxelarHookTest is Test {
// type(uint256).max = 115792089237316195423570985008687907853269984665640564039457584007913129639935. that's a big quote
uint256 expectedQuote = type(uint256).max;
bytes memory justRightCustomMetadata = BridgeAggregationHookMetadata
.formatMetadata(expectedQuote, 0, abi.encodePacked());
.formatMetadata(expectedQuote, abi.encodePacked());
bytes memory testMetadata = StandardHookMetadata.formatMetadata(
100,
100,
Expand Down

0 comments on commit c789755

Please sign in to comment.