diff --git a/script/Counter.s.sol b/script/Counter.s.sol deleted file mode 100644 index cdc1fe9..0000000 --- a/script/Counter.s.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterScript is Script { - Counter public counter; - - function setUp() public {} - - function run() public { - vm.startBroadcast(); - - counter = new Counter(); - - vm.stopBroadcast(); - } -} diff --git a/src/Counter.sol b/src/Counter.sol deleted file mode 100644 index aded799..0000000 --- a/src/Counter.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -contract Counter { - uint256 public number; - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } -} diff --git a/src/HyperlaneArbiter.sol b/src/HyperlaneArbiter.sol index cbc6dbe..8b7e8d1 100644 --- a/src/HyperlaneArbiter.sol +++ b/src/HyperlaneArbiter.sol @@ -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), + "", + 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"]; } function _handle( diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index 54b724f..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -}