Skip to content

Commit

Permalink
use internal virtual fns for quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 20, 2024
1 parent 023f7a7 commit 5e722be
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
67 changes: 54 additions & 13 deletions src/Tribunal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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;
}
}
11 changes: 5 additions & 6 deletions test/Tribunal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,29 +548,28 @@ 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();

assertEq(
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);
}

/**
Expand Down

0 comments on commit 5e722be

Please sign in to comment.