-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hyperlane Tribunal implementation #6
Open
0age
wants to merge
4
commits into
main
Choose a base branch
from
hyperlane-tribunal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"basicTransfer": "56867", | ||
"basicWithdrawal": "59992", | ||
"batchClaim": "112512", | ||
"batchClaimRegisteredWithDeposit": "112512", | ||
"batchClaimRegisteredWithDepositWithWitness": "113271", | ||
"batchClaimWithWitness": "113265", | ||
"batchDepositAndRegisterViaPermit2": "222059", | ||
"batchDepositAndRegisterWithWitnessViaPermit2": "222037", | ||
"batchTransfer": "81344", | ||
"batchWithdrawal": "100093", | ||
"claim": "56974", | ||
"claimAndWithdraw": "73432", | ||
"claimWithWitness": "59471", | ||
"depositAndRegisterViaPermit2": "124429", | ||
"depositBatchSingleERC20": "68050", | ||
"depositBatchSingleNative": "28353", | ||
"depositBatchViaPermit2NativeAndERC20": "129751", | ||
"depositBatchViaPermit2SingleERC20": "104905", | ||
"depositERC20AndURI": "67276", | ||
"depositERC20Basic": "67302", | ||
"depositERC20ViaPermit2AndURI": "98471", | ||
"depositETHAndURI": "26754", | ||
"depositETHBasic": "28391", | ||
"qualifiedBatchClaim": "114134", | ||
"qualifiedBatchClaimWithWitness": "113672", | ||
"qualifiedClaim": "60406", | ||
"qualifiedClaimWithWitness": "59098", | ||
"qualifiedSplitBatchClaim": "141486", | ||
"qualifiedSplitBatchClaimWithWitness": "141552", | ||
"qualifiedSplitClaim": "86977", | ||
"qualifiedSplitClaimWithWitness": "87452", | ||
"register": "25379", | ||
"splitBatchClaim": "140788", | ||
"splitBatchClaimWithWitness": "140749", | ||
"splitBatchTransfer": "110652", | ||
"splitBatchWithdrawal": "140361", | ||
"splitClaim": "86751", | ||
"splitClaimWithWitness": "86232", | ||
"splitTransfer": "82482", | ||
"splitWithdrawal": "93770" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.27; | ||
|
||
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 {Router} from "hyperlane/contracts/client/Router.sol"; | ||
|
||
string constant WITNESS_TYPESTRING = | ||
"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" | ||
); | ||
|
||
return abi.encodePacked( | ||
compact.arbiter, | ||
compact.sponsor, | ||
compact.nonce, | ||
compact.expires, | ||
compact.id, | ||
compact.maximumAmount, | ||
compact.allocatorSignature, | ||
compact.sponsorSignature, | ||
mandateHash, | ||
claimedAmount, | ||
claimant | ||
); | ||
} | ||
|
||
function decode(bytes calldata message) | ||
internal | ||
view | ||
returns ( | ||
address sponsor, | ||
uint256 nonce, | ||
uint256 expires, | ||
uint256 id, | ||
uint256 allocatedAmount, | ||
bytes calldata allocatorSignature, | ||
bytes calldata sponsorSignature, | ||
bytes32 witness, | ||
uint256 claimedAmount, | ||
address claimant | ||
) | ||
{ | ||
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]); | ||
claimedAmount = uint256(bytes32(message[328:360])); | ||
claimant = address(bytes20(message[360:380])); | ||
} | ||
} | ||
|
||
contract HyperlaneTribunal is Router, Tribunal { | ||
using Message for bytes; | ||
|
||
ITheCompactClaims public immutable theCompact; | ||
|
||
constructor(address _mailbox, address _theCompact) Router(_mailbox) { | ||
theCompact = ITheCompactClaims(_theCompact); | ||
} | ||
|
||
/** | ||
* @dev Process the directive for token claims | ||
* @param compact The claim parameters | ||
* @param mandateHash The derived mandate hash | ||
* @param directive The execution details | ||
* @param claimAmount The amount to claim | ||
*/ | ||
function _processDirective( | ||
Tribunal.Compact calldata compact, | ||
bytes32 mandateHash, | ||
Directive memory directive, | ||
uint256 claimAmount | ||
) internal virtual override { | ||
_Router_dispatch( | ||
uint32(compact.chainId), | ||
directive.dispensation, | ||
Message.encode(compact, mandateHash, claimAmount, directive.claimant), | ||
"", | ||
address(hook) | ||
); | ||
} | ||
|
||
/** | ||
* @dev Derive the quote for the dispensation required for | ||
* the directive for token claims | ||
* @param compact The claim parameters | ||
* @param mandateHash The derived mandate hash | ||
* @param claimant The address of the claimant | ||
* @param claimAmount The amount to claim | ||
* @return dispensation The quoted dispensation amount | ||
*/ | ||
function _quoteDirective( | ||
Tribunal.Compact calldata compact, | ||
bytes32 mandateHash, | ||
address claimant, | ||
uint256 claimAmount | ||
) internal view virtual override returns (uint256 dispensation) { | ||
return _Router_quoteDispatch( | ||
uint32(compact.chainId), Message.encode(compact, mandateHash, claimAmount, claimant), "", address(hook) | ||
); | ||
} | ||
|
||
function _handle( | ||
uint32, | ||
/*origin*/ | ||
bytes32, | ||
/*sender*/ | ||
bytes calldata message | ||
) internal override { | ||
( | ||
address sponsor, | ||
uint256 nonce, | ||
uint256 expires, | ||
uint256 id, | ||
uint256 allocatedAmount, | ||
bytes calldata allocatorSignature, | ||
bytes calldata sponsorSignature, | ||
bytes32 witness, | ||
uint256 claimedAmount, | ||
address claimant | ||
) = message.decode(); | ||
|
||
ClaimWithWitness memory claimPayload = ClaimWithWitness({ | ||
witnessTypestring: WITNESS_TYPESTRING, | ||
witness: witness, | ||
allocatorSignature: allocatorSignature, | ||
sponsorSignature: sponsorSignature, | ||
sponsor: sponsor, | ||
nonce: nonce, | ||
expires: expires, | ||
id: id, | ||
allocatedAmount: allocatedAmount, | ||
amount: claimedAmount, | ||
claimant: claimant | ||
}); | ||
|
||
theCompact.claim(claimPayload); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the mailbox will only call
handle
on the message headers recipient so this is unnecessary to include in the message body