From 5e722be4fa5aa0f427309a46ea028e76caa964a1 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:17:41 -0800 Subject: [PATCH] use internal virtual fns for quoting --- src/Tribunal.sol | 67 ++++++++++++++++++++++++++++++++++++--------- test/Tribunal.t.sol | 11 ++++---- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/Tribunal.sol b/src/Tribunal.sol index efcfcdf..9742730 100644 --- a/src/Tribunal.sol +++ b/src/Tribunal.sol @@ -141,19 +141,36 @@ contract Tribunal { * @notice Get a quote for the required dispensation amount * @param compact The claim parameters and constraints * @param mandate The settlement conditions and amount derivation parameters - * @param directive The execution details - * @return The suggested dispensation amount + * @param claimant The address of the claimant + * @return dispensation The suggested dispensation amount */ - function quote(Compact calldata compact, Mandate calldata mandate, Directive calldata directive) + function quote(Compact calldata compact, Mandate calldata mandate, address claimant) external view - returns (uint256) + returns (uint256 dispensation) { - compact; - mandate; - directive; - // TODO: Implement quote logic - return msg.sender.balance / 1000; + // Ensure that the mandate has not expired. + mandate.expires.later(); + + // Derive mandate hash. + bytes32 mandateHash = deriveMandateHash(mandate); + + // Derive and check claim hash + bytes32 claimHash = deriveClaimHash(compact, mandateHash); + if (_dispositions[claimHash]) { + revert AlreadyClaimed(); + } + + // Derive settlement and claim amounts. + (, uint256 claimAmount) = deriveAmounts( + compact.maximumAmount, + mandate.minimumAmount, + mandate.baselinePriorityFee, + mandate.scalingFactor + ); + + // Process the quote. + dispensation = _quoteDirective(compact, mandateHash, claimant, claimAmount); } /** @@ -169,8 +186,8 @@ contract Tribunal { { return ( "Mandate mandate)Mandate(uint256 chainId,address tribunal,address recipient,uint256 expires,address token,uint256 minimumAmount,uint256 baselinePriorityFee,uint256 scalingFactor,bytes32 salt)", - 2, - 3 + 4, + 5 ); } @@ -303,7 +320,31 @@ contract Tribunal { bytes32 mandateHash, Directive memory directive, uint256 claimAmount - ) internal { - // TODO: Implement directive processing + ) internal virtual { + // NOTE: Override & implement directive processing + } + + /** + * @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( + Compact memory compact, + bytes32 mandateHash, + address claimant, + uint256 claimAmount + ) internal view virtual returns (uint256 dispensation) { + compact; + mandateHash; + claimant; + claimAmount; + + // NOTE: Override & implement quote logic + return msg.sender.balance / 1000; } } diff --git a/test/Tribunal.t.sol b/test/Tribunal.t.sol index 582e829..84b2fdd 100644 --- a/test/Tribunal.t.sol +++ b/test/Tribunal.t.sol @@ -548,20 +548,19 @@ contract TribunalTest is Test { maximumAmount: 1 ether }); - Tribunal.Directive memory directive = - Tribunal.Directive({claimant: address(this), dispensation: 0}); + address claimant = address(this); // Fund the test contract with some ETH for the placeholder calculation vm.deal(address(this), 1000 ether); uint256 expectedQuote = address(this).balance / 1000; - assertEq(tribunal.quote(compact, mandate, directive), expectedQuote); + assertEq(tribunal.quote(compact, mandate, claimant), expectedQuote); } /** * @notice Verify that getCompactWitnessDetails returns correct values */ - function test_GetCompactWitnessDetails() public { + function test_GetCompactWitnessDetails() public view { (string memory witnessTypeString, uint256 tokenArg, uint256 amountArg) = tribunal.getCompactWitnessDetails(); @@ -569,8 +568,8 @@ contract TribunalTest is Test { witnessTypeString, "Mandate mandate)Mandate(uint256 chainId,address tribunal,address recipient,uint256 expires,address token,uint256 minimumAmount,uint256 baselinePriorityFee,uint256 scalingFactor,bytes32 salt)" ); - assertEq(tokenArg, 2); - assertEq(amountArg, 3); + assertEq(tokenArg, 4); + assertEq(amountArg, 5); } /**