Skip to content
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

add quote view fn & replace getCompactWitnessTypestring w/ getCompactWitnessDetails #3

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

50 changes: 48 additions & 2 deletions src/HyperlaneArbiter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,59 @@ contract HyperlaneArbiter is Router {
);
}

/**
* @notice Quotes a compact intent and returns the msg.value that should be provided
* cover all hyperlane fees (relay, etc).
* @param claimChain The chain ID of the claim.
* @param compact The compact intent to fill.
* @dev signatures must be compliant with https://eips.ethereum.org/EIPS/eip-2098
* @param allocatorSignature The allocator's signature.
* @param sponsorSignature The sponsor's signature.
* @return The quoted fee.
*/
function quote(
uint32 claimChain,
Compact calldata compact,
Intent calldata intent,
bytes calldata allocatorSignature,
bytes calldata sponsorSignature
) external view returns (uint256) {
require(block.chainid == intent.chainId, "invalid chain");

// TODO: support Permit2 fills
address filler = msg.sender;

return _Router_quoteDispatch(
claimChain,
Message.encode(compact, allocatorSignature, sponsorSignature, hash(intent), intent.fee, filler),
"",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we dont populate anything here, the handle function is assumed to have a gas limit of 50k
we may need to adjust this, have you successfully used these quotes in prod yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet — open question on whether to just build in an approximate buffer and let filler work out the exact quoted fee or if the UI should derive it locally

address(hook)
);
}

function hash(Intent memory intent) public pure returns (bytes32) {
return
keccak256(abi.encode(TYPEHASH, intent.fee, intent.chainId, intent.token, intent.recipient, intent.amount));
}

function getCompactWitnessTypestring() external pure returns (string memory) {
return WITNESS_TYPESTRING;
function getCompactWitnessDetails()
external
pure
returns (
string memory typestring,
string[] memory compactTokenArguments,
string[3][] memory customTokenArguments
)
{
typestring = WITNESS_TYPESTRING;

// Arguments that refer to some amount of the token in the resource lock
compactTokenArguments = new string[](1);
compactTokenArguments[0] = "fee";

// Arguments that refer to some amount of an arbitrary chain + token combination
customTokenArguments = new string[3][](1);
customTokenArguments[0] = ["intent.chainId", "intent.token", "intent.amount"];
Comment on lines +174 to +179
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be very happy to just adopt whatever standard struct you propose on the compact
this would facilitate both users and fillers to understand the eip712 payloads better

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do feel like some form of JSON payload that lays out the typestring as well as the various semantic context and relations between the arguments could be a better way than .. whatever this is 🤣

that said, it does get the job done for just detecting token names / decimals to use 🤷

}

function _handle(
Expand Down
24 changes: 0 additions & 24 deletions test/Counter.t.sol

This file was deleted.