minGrossForNet
Smallest gross USDC such that net after a fee rate is at least the target.
Inverse of net = gross − ceil(gross × rate / 1e8). Used by exact-output buys to size the wallet's USDC cap so the curve still receives costRaw after the 1.25% buy fee.
Rounds up so the net cannot fall short.
Import
import { minGrossForNet } from "@repo/contract-client/math";
Usage
import { parseUsdc } from "@repo/contract-client";
import { asMicroBps } from "@repo/contract-client/types";
import { minGrossForNet } from "@repo/contract-client/math";
const gross = minGrossForNet(parseUsdc("10"), asMicroBps(1_250_000n));
Return Value
UsdcRaw — fee-inclusive gross. 0n in, 0n out.
Parameters
net
- Type:
UsdcRaw
Desired amount after the fee (curve cost, or user proceeds).
minGrossForNet(curveCost, asMicroBps(1_250_000n));
rate
- Type:
MicroBps
Same units as splitFee. Must be < 100_000_000.
minGrossForNet(parseUsdc("10"), asMicroBps(1_250_000n));
Error
ProtocolRevertError ZeroAmount if the rate is 100% (fee would consume all).