Skip to content

Commit

Permalink
integrate Hyperlane with Tribunal
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 20, 2024
1 parent bed0240 commit d8ae476
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lib/tribunal
94 changes: 43 additions & 51 deletions src/HyperlaneTribunal.sol
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import {TheCompact} from "the-compact/src/TheCompact.sol";
import {ITheCompactClaims} from "the-compact/src/interfaces/ITheCompactClaims.sol";
import {ClaimWithWitness} from "the-compact/src/types/Claims.sol";
import {Compact} from "the-compact/src/types/EIP712Types.sol";
import {Tribunal} from "tribunal/Tribunal.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {Router} from "hyperlane/contracts/client/Router.sol";

struct Intent {
uint256 fee;
uint32 chainId;
address token;
address recipient;
uint256 amount;
}

string constant TYPESTRING = "Intent(uint256 fee,uint32 chainId,address token,address recipient,uint256 amount)";
bytes32 constant TYPEHASH = keccak256(bytes(TYPESTRING));

string constant WITNESS_TYPESTRING =
"Intent intent)Intent(uint256 fee,uint32 chainId,address token,address recipient,uint256 amount)";
"Mandate mandate)Mandate(uint256 chainId,address tribunal,address recipient,uint256 expires,address token,uint256 minimumAmount,uint256 baselinePriorityFee,uint256 scalingFactor,bytes32 salt)";

library Message {
function encode(
Tribunal.Compact calldata compact,
bytes32 mandateHash,
uint256 claimedAmount,
address claimant
) internal pure returns (bytes memory) {
require(compact.allocatorSignature.length == 64 && compact.sponsorSignature.length == 64, "invalid signature length");
function encode(Tribunal.Compact calldata compact, bytes32 mandateHash, uint256 claimedAmount, address claimant)
internal
pure
returns (bytes memory)
{
require(
compact.allocatorSignature.length == 64 && compact.sponsorSignature.length == 64, "invalid signature length"
);

return abi.encodePacked(
compact.arbiter,
Expand All @@ -50,26 +38,29 @@ library Message {

function decode(bytes calldata message)
internal
pure
view
returns (
// TODO: calldata
Compact memory compact,
address sponsor,
uint256 nonce,
uint256 expires,
uint256 id,
uint256 allocatedAmount,
bytes calldata allocatorSignature,
bytes calldata sponsorSignature,
bytes32 witness,
uint256 claimedAmount,
address claimant
)
{
assert(message.length == 380);
compact = Compact({
arbiter: address(bytes20(message[0:20])),
sponsor: address(bytes20(message[20:40])),
nonce: uint256(bytes32(message[40:72])),
expires: uint256(bytes32(message[72:104])),
id: uint256(bytes32(message[104:136])),
amount: uint256(bytes32(message[136:168]))
});
require(message.length == 380, "invalid message length");
address arbiter = address(bytes20(message[0:20]));
require(arbiter == address(this), "invalid arbiter");

sponsor = address(bytes20(message[20:40]));
nonce = uint256(bytes32(message[40:72]));
expires = uint256(bytes32(message[72:104]));
id = uint256(bytes32(message[104:136]));
allocatedAmount = uint256(bytes32(message[136:168]));
allocatorSignature = message[168:232];
sponsorSignature = message[232:296];
witness = bytes32(message[296:328]);
Expand All @@ -81,10 +72,10 @@ library Message {
contract HyperlaneTribunal is Router, Tribunal {
using Message for bytes;

TheCompact public immutable theCompact;
ITheCompactClaims public immutable theCompact;

constructor(address _mailbox, address _theCompact) Router(_mailbox) {
theCompact = TheCompact(_theCompact);
theCompact = ITheCompactClaims(_theCompact);
}

/**
Expand All @@ -95,13 +86,13 @@ contract HyperlaneTribunal is Router, Tribunal {
* @param claimAmount The amount to claim
*/
function _processDirective(
Tribunal.Compact memory compact,
Tribunal.Compact calldata compact,
bytes32 mandateHash,
Directive memory directive,
uint256 claimAmount
) internal virtual override {
_Router_dispatch(
compact.chainId,
uint32(compact.chainId),
directive.dispensation,
Message.encode(compact, mandateHash, claimAmount, directive.claimant),
"",
Expand All @@ -119,16 +110,13 @@ contract HyperlaneTribunal is Router, Tribunal {
* @return dispensation The quoted dispensation amount
*/
function _quoteDirective(
Tribunal.Compact memory compact,
Tribunal.Compact calldata compact,
bytes32 mandateHash,
address claimant,
uint256 claimAmount
) internal view virtual override returns (uint256 dispensation) {
return _Router_quoteDispatch(
compact.chainId,
Message.encode(compact, mandateHash, claimAmount, claimant),
"",
address(hook)
uint32(compact.chainId), Message.encode(compact, mandateHash, claimAmount, claimant), "", address(hook)
);
}

Expand All @@ -140,9 +128,13 @@ contract HyperlaneTribunal is Router, Tribunal {
bytes calldata message
) internal override {
(
Compact memory compact,
bytes memory allocatorSignature,
bytes memory sponsorSignature,
address sponsor,
uint256 nonce,
uint256 expires,
uint256 id,
uint256 allocatedAmount,
bytes calldata allocatorSignature,
bytes calldata sponsorSignature,
bytes32 witness,
uint256 claimedAmount,
address claimant
Expand All @@ -153,11 +145,11 @@ contract HyperlaneTribunal is Router, Tribunal {
witness: witness,
allocatorSignature: allocatorSignature,
sponsorSignature: sponsorSignature,
sponsor: compact.sponsor,
nonce: compact.nonce,
expires: compact.expires,
id: compact.id,
allocatedAmount: compact.amount,
sponsor: sponsor,
nonce: nonce,
expires: expires,
id: id,
allocatedAmount: allocatedAmount,
amount: claimedAmount,
claimant: claimant
});
Expand Down

0 comments on commit d8ae476

Please sign in to comment.