Skip to content

PoC rate ratifier#841

Draft
QGarchery wants to merge 8 commits into
mainfrom
feat-rate-ratifier
Draft

PoC rate ratifier#841
QGarchery wants to merge 8 commits into
mainfrom
feat-rate-ratifier

Conversation

@QGarchery
Copy link
Copy Markdown
Collaborator

@QGarchery QGarchery commented May 11, 2026

Notes:

  • implements a rate ratifier, where the tick is replaced by a limit rate, takers can choose a tick that leads to better rate for the maker than the limit rate (and a worse rate for them)
    • we could check that the taker chose the best tick easily, but we could not compute that tick easily (it requires priceToTick)
  • the signed message is called a rate offer which, compared to an offer, replaces the tick by the limit price (happens to have the same uint256 type)
  • we could also have a Merkle tree of rate offers, I chose not to for simplicity in this POC
  • see comments below for implementation details and points of discussion

@QGarchery QGarchery self-assigned this May 11, 2026
Comment thread src/ratifiers/RateRatifier.sol Outdated
Comment thread src/ratifiers/HashLib.sol Outdated
Comment on lines +71 to +72
/// @dev Computes the EIP-712 hash struct of a RateOffer (offer with `tick` replaced by `rate`).
function hashRateOffer(Offer memory offer, uint256 rate) internal pure returns (bytes32) {
Copy link
Copy Markdown
Collaborator Author

@QGarchery QGarchery May 11, 2026

Choose a reason for hiding this comment

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

We could also factorize with hashOffer

Comment on lines +7 to +10
bytes constant RATE_OFFER_TYPE =
"RateOffer(Obligation obligation,bool buy,address maker,uint256 start,uint256 expiry,uint256 rate,bytes32 group,bytes32 session,address callback,bytes callbackData,address receiverIfMakerIsSeller,address ratifier,bool reduceOnly,uint256 maxUnits,uint256 maxSellerAssets,uint256 maxBuyerAssets)";
/// @dev keccak256(bytes.concat(RATE_OFFER_TYPE, COLLATERAL_PARAMS_TYPE, OBLIGATION_TYPE))
bytes32 constant RATE_OFFER_TYPEHASH = 0x90e9f9e41e2cb91ddebe5f4e0924a3f0bc32d2c1048017a241339fabf364502c;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We could reuse OFFER_TYPEHASH and there would be no risk of collision, since EcrecoverRatifier always uses a Merkle tree. Also the current typehash doesn't correspond to a concrete struct.
Still prefer current code slightly, as it separates things even more explicitly. Minor benefit: a future ratifier could use a signature over a concrete Offer without risk of collision with this ratifier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is no collision anyway because EIP712 includes the contract address right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

right, no collision in what is signed since the ratifiers are the verifyingContract as defined in EIP712
Still could be a bit confusing to have a tick field hold a rate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

agree on field confusion

@QGarchery QGarchery marked this pull request as ready for review May 11, 2026 20:34
@QGarchery QGarchery changed the title Rate ratifier (WIP) PoC rate ratifier May 11, 2026
@QGarchery QGarchery requested review from MathisGD, adhusson and peyha May 11, 2026 20:35
chatgpt-codex-connector[bot]

This comment was marked as outdated.

Comment thread src/ratifiers/RateRatifier.sol
Comment thread src/ratifiers/interfaces/IRateRatifier.sol Outdated
QGarchery and others added 3 commits May 12, 2026 10:49
Co-authored-by: Adrien Husson <adhusson@gmail.com>
Signed-off-by: Quentin Garchery <garchery.quentin@gmail.com>
@MathisGD MathisGD marked this pull request as draft May 12, 2026 13:01
@MathisGD MathisGD marked this pull request as draft May 12, 2026 13:01
@MathisGD MathisGD marked this pull request as draft May 12, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants