Skip to content

Commit 2d620ea

Browse files
committed
refactor(portfolio-contract): Define a applyHaircut helper function
1 parent 11dfea7 commit 2d620ea

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/portfolio-contract/tools/plan-solve.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ const replaceOrInit = <K, V>(
3737
map.set(key, callback(old, key, exists));
3838
};
3939

40+
/**
41+
* Reduce a value by a natural number of basis points, rounding the result down
42+
* (e.g., 1 bp of 10k is exactly 1, so subtracting 1 bp from any value up to 10k
43+
* reduces it by a full unit).
44+
*/
45+
export const applyHaircut = (n: bigint, bps: bigint) =>
46+
(n * (10000n - bps)) / 10000n;
47+
4048
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4149
const trace = makeTracer('solve');
4250

@@ -453,7 +461,7 @@ export const rebalanceMinCostFlowSteps = async (
453461
// HACK: subtract 1n to avoid rounding errors in Noble per
454462
// https://github.com/Agoric/agoric-private/issues/415
455463
const usdnOut =
456-
(BigInt(flow) * (10000n - BigInt(edge.variableFee))) / 10000n - 1n;
464+
applyHaircut(BigInt(flow), BigInt(edge.variableFee)) - 1n;
457465
details = { detail: { usdnOut } };
458466
break;
459467
}

0 commit comments

Comments
 (0)