Skip to content

ProfitClient: make the policy registry the central profitability pivot#3472

Open
droplet-rl wants to merge 1 commit into
masterfrom
droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log
Open

ProfitClient: make the policy registry the central profitability pivot#3472
droplet-rl wants to merge 1 commit into
masterfrom
droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log

Conversation

@droplet-rl

@droplet-rl droplet-rl commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Squashes the policy registry into a single RelayerPolicy type. The default policy is just a regular policy named default, appended to this.policies at construct time with an empty routes Map (catch-all match) and getters that surface defaultMinRelayerFeePct / gasMultiplier from live instance state.

type RelayerPolicy = {
  name: string;
  routes: Map<string, PolicyRoute>;       // empty Map = catch-all
  readonly minFeePct?: BigNumber;
  readonly gasMultiplier?: BigNumber;
};

Every per-deposit profitability decision walks this.policies once. 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 in resolvePolicy / minRelayerFeePct / resolveGasMultiplier.

Also adds a debug log (at: "ProfitClient#policyMatch") whenever a non-default policy matches a deposit. The log records depositId, originChainId, destinationChainId, srcSymbol, dstSymbol, inputAmount, outputAmount, the matched policy name, the resolved minRelayerFeePct / gasMultiplier, and boolean flags indicating whether each value came from the policy or the default fallback.

Breaking changes

  • The legacy per-route/token/chain MIN_RELAYER_FEE_PCT_* and RELAYER_GAS_MULTIPLIER_* env-var lookup chain is removed. Operators that need per-route overrides should define a RELAYER_POLICIES entry. 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.
  • gasMessageMultiplier is 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 a RELAYER_POLICIES entry for a message-specific gas multiplier.

Test plan

  • yarn tsc --noEmit passes.
  • yarn lint passes.
  • yarn test test/ProfitClient.ConsiderProfitability.ts passes (11 tests).

🤖 Generated with Claude Code

@droplet-rl droplet-rl force-pushed the droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log branch from b16e9c1 to 5b5d5c4 Compare June 9, 2026 05:35
@droplet-rl droplet-rl changed the title ProfitClient: log when a RELAYER_POLICIES entry matches a deposit ProfitClient: resolve matching policy once per deposit Jun 9, 2026
@droplet-rl droplet-rl force-pushed the droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log branch from 5b5d5c4 to 64e2130 Compare June 9, 2026 07:55
@droplet-rl droplet-rl changed the title ProfitClient: resolve matching policy once per deposit ProfitClient: make the policy registry the central profitability pivot Jun 9, 2026
@droplet-rl droplet-rl force-pushed the droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log branch 3 times, most recently from 434c24e to 97b34f8 Compare June 9, 2026 09:20
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>
@droplet-rl droplet-rl force-pushed the droplet/T90K0AL22-C07J5CDQTLL-1780933024-345539-policy-log branch from 97b34f8 to f4a80a1 Compare June 9, 2026 09:32
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