ProfitClient: make the policy registry the central profitability pivot#3472
Open
droplet-rl wants to merge 1 commit into
Open
ProfitClient: make the policy registry the central profitability pivot#3472droplet-rl wants to merge 1 commit into
droplet-rl wants to merge 1 commit into
Conversation
b16e9c1 to
5b5d5c4
Compare
5b5d5c4 to
64e2130
Compare
434c24e to
97b34f8
Compare
Adds a debug log from getFillProfitability whenever a RELAYER_POLICIES
registry entry matches the deposit being evaluated, and reshapes the
surrounding code so every per-deposit profitability decision flows through a
unified policy registry.
The default policy is now just a regular RelayerPolicy named "default",
appended to `this.policies` inline at the end of the constructor with an
empty `routes` Map (catch-all match) and getters that surface
`defaultMinRelayerFeePct` / `gasMultiplier` from live instance state. A
single `resolvePolicy(deposit)` iterates the registry once and returns the
first matching policy plus the first-defined minFeePct / gasMultiplier;
named policies with partial coverage fall through to the default.
Type:
```ts
type RelayerPolicy = {
name: string;
routes: Map<string, PolicyRoute>; // empty Map = catch-all
readonly minFeePct?: BigNumber;
readonly gasMultiplier?: BigNumber;
};
```
- `this.policies = [...this.decodePolicies(), { name: "default", ... }]`.
- `resolvePolicy` accepts `Pick<Deposit, ...>` and inlines the
match-predicate so there's a single iteration loop.
- Public `minRelayerFeePct` and `resolveGasMultiplier` are one-line
delegations to `resolvePolicy`.
- `getFillProfitability` calls `resolvePolicy` once, logs the match, and
passes minRelayerFeePct into `calculateFillProfitability` — the existing
log reads `gasMultiplier` off the returned `FillProfit`, so no plumbing
through `calculateFillProfitability` / `estimateFillCost`.
Breaking changes versus the prior behaviour:
- The legacy per-route/token/chain `MIN_RELAYER_FEE_PCT_*` and
`RELAYER_GAS_MULTIPLIER_*` env-var override chain is removed. Operators
that need per-route overrides should define a `RELAYER_POLICIES` entry.
- `gasMessageMultiplier` is no longer applied to message-bearing deposits.
The constructor arg is still accepted and validated for backwards-
compatibility, but not consulted at deposit time.
The three legacy tests covering the dropped per-route env-var support are
removed; the policy-registry test exercises the replacement behaviour and
includes a fallback-to-default-policy assertion.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
97b34f8 to
f4a80a1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Squashes the policy registry into a single
RelayerPolicytype. The default policy is just a regular policy nameddefault, appended tothis.policiesat construct time with an emptyroutesMap (catch-all match) and getters that surfacedefaultMinRelayerFeePct/gasMultiplierfrom live instance state.Every per-deposit profitability decision walks
this.policiesonce. For each knob the first matching policy that defines a value wins; named policies with partial coverage fall through to the default. No discriminated union, no special-case branches inresolvePolicy/minRelayerFeePct/resolveGasMultiplier.Also adds a
debuglog (at: "ProfitClient#policyMatch") whenever a non-default policy matches a deposit. The log recordsdepositId,originChainId,destinationChainId,srcSymbol,dstSymbol,inputAmount,outputAmount, the matchedpolicyname, the resolvedminRelayerFeePct/gasMultiplier, and boolean flags indicating whether each value came from the policy or the default fallback.Breaking changes
MIN_RELAYER_FEE_PCT_*andRELAYER_GAS_MULTIPLIER_*env-var lookup chain is removed. Operators that need per-route overrides should define aRELAYER_POLICIESentry. The three legacy tests covering the dropped behaviour are removed; the policy-registry test covers the replacement behaviour and includes a fallback-to-default-policy assertion.gasMessageMultiplieris no longer applied to message-bearing deposits. The constructor arg is still accepted and validated for backwards-compatibility, but it is not consulted at deposit time. Define aRELAYER_POLICIESentry for a message-specific gas multiplier.Test plan
yarn tsc --noEmitpasses.yarn lintpasses.yarn test test/ProfitClient.ConsiderProfitability.tspasses (11 tests).🤖 Generated with Claude Code