@lelantos-org/sdk / protocol / toTokenUnitsAtRate
Function: toTokenUnitsAtRate()
ts
function toTokenUnitsAtRate(
circuitAmount,
scale,
rate,
opts?
): TokenAmount;Defined in: @lelantos-org/sdk/dist/protocol/units.d.ts:75
Circuit units → ERC-20 base units at a pool-measured rate. Use this over toTokenUnits for any figure someone is charged; see YieldRate.
undefined, or a rate with no units outstanding, yields circuit * scale: an empty pool has no ratio and one unit is worth exactly scale, which pins a fresh asset's index to RAY.
A nonzero supply with zero gross is not that case: the venue lost everything, the contract pays out zero, and so does this. Treating it as an empty pool would price worthless units at face value.
Rounds up by default because the caller is paying in: rounding down under-signs the Permit2 ceiling.
Parameters
| Parameter | Type |
|---|---|
circuitAmount | CircuitAmount |
scale | bigint |
rate | YieldRate | undefined |
opts? | { round?: "down" | "up"; } |
opts.round? | "down" | "up" |