fix: run Surplus seller continuously

This commit is contained in:
david
2026-08-28 09:27:53 +02:00
parent 41820b11bb
commit cd3ea734e3
4 changed files with 29 additions and 13 deletions

View File

@@ -145,9 +145,10 @@ OPENROUTER_CAPACITY_BASE_URL=https://openrouter.ai/api
SURPLUS_SELLER_WALLET=0x0000000000000000000000000000000000000000
SURPLUS_PAYOUT_ADDRESS=0x0000000000000000000000000000000000000000
# The controller discovers all fixed-price text models and selects one by
# current demand. It keeps only one active proof offer.
SURPLUS_PER_OFFER_CAP_USD=1.00
SURPLUS_AGGREGATE_CAP_USD=1.00
# current demand. It keeps only one active offer. At the default 490 bps
# recovery floor, a $0.05 seller cap bounds upstream spend near $1.02 per day.
SURPLUS_PER_OFFER_CAP_USD=0.05
SURPLUS_AGGREGATE_CAP_USD=0.05
SURPLUS_OPENROUTER_RESERVE_USD=1.00
SURPLUS_OPENROUTER_MAX_LIMIT_USD=20.00
SURPLUS_MIN_RECOVERY_BPS=490

View File

@@ -72,11 +72,11 @@ export function loadSurplusManagerConfig(
providerBaseUrl,
capacityBaseUrl,
perOfferCapUsd: usd(
env.SURPLUS_PER_OFFER_CAP_USD ?? "1.00",
env.SURPLUS_PER_OFFER_CAP_USD ?? "0.05",
"SURPLUS_PER_OFFER_CAP_USD",
),
aggregateCapUsd: usd(
env.SURPLUS_AGGREGATE_CAP_USD ?? "1.00",
env.SURPLUS_AGGREGATE_CAP_USD ?? "0.05",
"SURPLUS_AGGREGATE_CAP_USD",
),
sellerWallet,

View File

@@ -212,7 +212,12 @@ export class SurplusSellerController {
}
const allowance = await this.allowance.readAllowance();
this.assertAllowance(allowance, parseUsdDecimal(this.config.aggregateCapUsd, "ceil"));
this.assertAllowance(
allowance,
this.providerExposureUsdNanos(
parseUsdDecimal(this.config.aggregateCapUsd, "ceil"),
),
);
const [discovered, markets] = await Promise.all([
this.client.discoverModels(
this.config.providerApiKey,
@@ -444,7 +449,9 @@ export class SurplusSellerController {
const allowance = await this.allowance.readAllowance();
this.assertAllowance(
allowance,
parseUsdDecimal(this.config.perOfferCapUsd, "ceil"),
this.providerExposureUsdNanos(
parseUsdDecimal(this.config.perOfferCapUsd, "ceil"),
),
);
const baselineAllowance = BigInt(
currentState.intent.baselineRemainingUsdNanos,
@@ -452,7 +459,9 @@ export class SurplusSellerController {
const providerSpend = baselineAllowance > allowance.remainingUsdNanos
? baselineAllowance - allowance.remainingUsdNanos
: 0n;
const spendCap = parseUsdDecimal(this.config.perOfferCapUsd, "ceil");
const spendCap = this.providerExposureUsdNanos(
parseUsdDecimal(this.config.perOfferCapUsd, "ceil"),
);
if (this.config.stopAfterTrades > 0 && providerSpend >= spendCap) {
const stopping: SurplusControllerState = {
version: 1,
@@ -684,6 +693,12 @@ export class SurplusSellerController {
}
}
private providerExposureUsdNanos(sellerCapUsdNanos: bigint): bigint {
const numerator = sellerCapUsdNanos * 10_000n;
const denominator = BigInt(this.config.recoveryBps);
return (numerator + denominator - 1n) / denominator;
}
private assertAllowance(
allowance: OpenRouterKeyAllowance,
exposureUsdNanos: bigint,