fix: quote Surplus text offers by multiplier
This commit is contained in:
@@ -222,7 +222,7 @@ describe("SurplusClient", () => {
|
||||
expect(String(fetchFn.mock.calls[1][0])).toContain("alpha%3Amodel");
|
||||
});
|
||||
|
||||
it("sends one absolute PATCH with plain USD prices and the cap", async () => {
|
||||
it("sends one absolute cost-multiplier PATCH with the cap", async () => {
|
||||
let request: RequestInit | undefined;
|
||||
const client = new SurplusClient({
|
||||
apiBaseUrl: "https://api.surplusintelligence.ai",
|
||||
@@ -235,17 +235,15 @@ describe("SurplusClient", () => {
|
||||
});
|
||||
|
||||
await client.updateOffer("offer/one", {
|
||||
inputUsdPer1m: 0.003972,
|
||||
outputUsdPer1m: 0.007944,
|
||||
costMultiplier: 0.04995,
|
||||
dailyCapUsd: 1,
|
||||
idempotencyKey: "mutation-1",
|
||||
});
|
||||
|
||||
expect(request?.method).toBe("PATCH");
|
||||
expect(JSON.parse(String(request?.body))).toEqual({
|
||||
pricing_mode: "per_token",
|
||||
price_input_per_1m: 0.003972,
|
||||
price_output_per_1m: 0.007944,
|
||||
pricing_mode: "cost_multiplier",
|
||||
cost_multiplier: 0.04995,
|
||||
cap_daily_usd: 1,
|
||||
});
|
||||
const headers = new Headers(request?.headers);
|
||||
|
||||
@@ -147,8 +147,9 @@ class FakeSurplusClient implements SurplusControllerClient {
|
||||
sellerBaseUrl: input.sellerBaseUrl,
|
||||
status: "active",
|
||||
capDailyUsd: input.dailyCapUsd,
|
||||
inputMicroUsdPer1m: Math.round(input.inputUsdPer1m * 1_000_000),
|
||||
outputMicroUsdPer1m: Math.round(input.outputUsdPer1m * 1_000_000),
|
||||
costMultiplierPpm: Math.round(input.costMultiplier * 1_000_000),
|
||||
inputMicroUsdPer1m: Math.floor(79_520 * input.costMultiplier),
|
||||
outputMicroUsdPer1m: Math.floor(159_040 * input.costMultiplier),
|
||||
};
|
||||
return this.offer.id;
|
||||
}
|
||||
@@ -157,8 +158,15 @@ class FakeSurplusClient implements SurplusControllerClient {
|
||||
this.externalCalls += 1;
|
||||
this.patchPayload = patch;
|
||||
if (!this.offer) throw new Error("missing fake offer");
|
||||
this.offer.inputMicroUsdPer1m = Math.round(patch.inputUsdPer1m * 1_000_000);
|
||||
this.offer.outputMicroUsdPer1m = Math.round(patch.outputUsdPer1m * 1_000_000);
|
||||
this.offer.costMultiplierPpm = Math.round(
|
||||
patch.costMultiplier * 1_000_000,
|
||||
);
|
||||
this.offer.inputMicroUsdPer1m = Math.floor(
|
||||
79_520 * patch.costMultiplier,
|
||||
);
|
||||
this.offer.outputMicroUsdPer1m = Math.floor(
|
||||
159_040 * patch.costMultiplier,
|
||||
);
|
||||
this.offer.capDailyUsd = patch.dailyCapUsd;
|
||||
}
|
||||
|
||||
@@ -223,8 +231,7 @@ describe("SurplusSellerController", () => {
|
||||
expect(client.createCalls).toBe(1);
|
||||
expect(client.createdPayload).toMatchObject({
|
||||
model: "beta-model",
|
||||
inputUsdPer1m: 0.003972,
|
||||
outputUsdPer1m: 0.007944,
|
||||
costMultiplier: 0.04995,
|
||||
dailyCapUsd: 1,
|
||||
payoutAddress: SELLER_WALLET,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
quoteSurplusPrice,
|
||||
quoteSurplusMultiplier,
|
||||
} from "../../supplier/src/surplus/policy.js";
|
||||
import {
|
||||
eligibleCompetitors,
|
||||
@@ -41,8 +41,8 @@ function market(model: string, requests24h: number): SurplusMarketSummary {
|
||||
}
|
||||
|
||||
describe("Surplus bounded price policy", () => {
|
||||
it("uses exact recovery floors and undercuts in integer micro-USD", () => {
|
||||
const quote = quoteSurplusPrice({
|
||||
it("uses an exact recovery multiplier and undercuts in integer micro-USD", () => {
|
||||
const quote = quoteSurplusMultiplier({
|
||||
upstreamInputMicroUsdPer1m: 79_520,
|
||||
upstreamOutputMicroUsdPer1m: 159_040,
|
||||
recoveryBps: 490,
|
||||
@@ -54,17 +54,16 @@ describe("Surplus bounded price policy", () => {
|
||||
}],
|
||||
});
|
||||
|
||||
expect(quote.floorInputMicroUsdPer1m).toBe(3_897);
|
||||
expect(quote.floorOutputMicroUsdPer1m).toBe(7_793);
|
||||
expect(quote.floorMultiplierPpm).toBe(49_000);
|
||||
expect(quote.costMultiplierPpm).toBe(49_950);
|
||||
expect(quote.costMultiplier).toBe(0.04995);
|
||||
expect(quote.inputMicroUsdPer1m).toBe(3_972);
|
||||
expect(quote.outputMicroUsdPer1m).toBe(7_944);
|
||||
expect(quote.inputUsdPer1m).toBe(0.003972);
|
||||
expect(quote.outputUsdPer1m).toBe(0.007944);
|
||||
expect(quote.competitive).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the recovery floor when the cheapest offer is too low", () => {
|
||||
const quote = quoteSurplusPrice({
|
||||
const quote = quoteSurplusMultiplier({
|
||||
upstreamInputMicroUsdPer1m: 79_520,
|
||||
upstreamOutputMicroUsdPer1m: 159_040,
|
||||
recoveryBps: 490,
|
||||
@@ -76,8 +75,8 @@ describe("Surplus bounded price policy", () => {
|
||||
}],
|
||||
});
|
||||
|
||||
expect(quote.inputMicroUsdPer1m).toBe(3_897);
|
||||
expect(quote.outputMicroUsdPer1m).toBe(7_793);
|
||||
expect(quote.floorMultiplierPpm).toBe(49_000);
|
||||
expect(quote.costMultiplierPpm).toBe(49_000);
|
||||
expect(quote.competitive).toBe(false);
|
||||
});
|
||||
|
||||
@@ -91,9 +90,9 @@ describe("Surplus bounded price policy", () => {
|
||||
const left = { id: "left", inputMicroUsdPer1m: 100, outputMicroUsdPer1m: 300 };
|
||||
const right = { id: "right", inputMicroUsdPer1m: 200, outputMicroUsdPer1m: 200 };
|
||||
|
||||
expect(quoteSurplusPrice({ ...input, competitors: [right, left] }).competitorId)
|
||||
expect(quoteSurplusMultiplier({ ...input, competitors: [right, left] }).competitorId)
|
||||
.toBe("left");
|
||||
expect(quoteSurplusPrice({ ...input, competitors: [left, right] }).competitorId)
|
||||
expect(quoteSurplusMultiplier({ ...input, competitors: [left, right] }).competitorId)
|
||||
.toBe("left");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user