> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# svm venues: shared helpers

> 100 exports shared across Solana venue integrations: math, types, registry, PDA memos, stable and scale helpers, tree walk.

Helpers shared by the venue integrations under `svm/venues`.

<Note>
  Generated from the type declarations shipped in `@eco-incorp/sauce` 0.99.4. Each entry shows the package authors' JSDoc and declaration for this SDK version. For runtime compatibility and deployed addresses, see [architecture and deployments](/programmable-transactions/sauce/architecture-and-deployments).
</Note>

### `ceilDiv`

*Function* · `sdk/dist/svm/venues/math.d.ts`

Ceiling division: smallest q with q \* b >= a. Non-negative dividends only.

```typescript theme={null}
export declare function ceilDiv(a: bigint, b: bigint): bigint;
```

### `readUintLE`

*Function* · `sdk/dist/svm/venues/math.d.ts`

Little-endian unsigned field read - the TS mirror of the compiler's
accountUint(ref, offset, width). All seven venues are pure-LE; BE never
occurs. width is in bytes, 1..=32 (SPL token amount = readUintLE(data, 64, 8)).

```typescript theme={null}
export declare function readUintLE(data: Uint8Array, offset: number, width: number): bigint;
```

### `assertOracleExponent`

*Function* · `sdk/dist/svm/venues/oracle-exponent.d.ts`

Deterministic range gate: same bytes in, same throw out, before any BigInt
power is constructed. Rejects the whole out-of-range `i32` domain, extremes
included. Note what `Math.abs` does NOT do here: `Math.abs(i32::MIN)` is
2147483648 - a perfectly ordinary, safe JS integer that sails into `BigInt`
intact. Taking an absolute value bounds the SIGN, never the MAGNITUDE, so the
gate has to reject on the value itself.

* @param provider which account format the exponent was decoded from
* @param expo the decoded, sign-corrected `i32`
* @param context caller-supplied identity (venue, pool, account) for the error

```typescript theme={null}
export declare function assertOracleExponent(provider: OracleExponentProvider, expo: number, context: string): void;
```

### `OracleExponentProvider`

*Type* · `sdk/dist/svm/venues/oracle-exponent.d.ts`

The oracle account FORMATS these adapters decode an exponent out of. The
issuer is Pyth in both cases; the formats differ in how the bound reaches
them, which is why they are separate rows rather than one global constant.

```typescript theme={null}
export type OracleExponentProvider = "pyth-price-update-v2" | "pyth-v2-price-account";
```

### `PYTH_MAX_NUM_DECIMALS`

*Variable* · `sdk/dist/svm/venues/oracle-exponent.d.ts`

`MAX_NUM_DECIMALS` as the Pythnet oracle program itself defines it:
pyth-network/pyth-client, `program/rust/src/c_oracle_header.rs` -
/// Bound on the range of the exponent in price accounts. This number is set
/// such that the PD-based EMA computation does not lose too much precision.
pub const MAX\_NUM\_DECIMALS: i32 = 12;

enforced by `utils::check_exponent_range`, which asserts
`(-MAX_NUM_DECIMALS..=MAX_NUM_DECIMALS).contains(&expo)`. That check runs in
`processor::add_price` and `processor::init_price` - the only two instructions
in the program that ever write `price_data.exponent` - so no Pyth price
account can carry an exponent outside \[-12, 12].

```typescript theme={null}
PYTH_MAX_NUM_DECIMALS = 12
```

### `OracleExponentRange`

*Interface* · `sdk/dist/svm/venues/oracle-exponent.d.ts`

```typescript theme={null}
export interface OracleExponentRange {
    readonly min: number;
    readonly max: number;
    readonly provenance: string;
}
```

### `ORACLE_EXPONENT_RANGES`

*Variable* · `sdk/dist/svm/venues/oracle-exponent.d.ts`

```typescript theme={null}
ORACLE_EXPONENT_RANGES: Readonly<Record<OracleExponentProvider, OracleExponentRange>>
```

### `configurePdaMemo`

*Function* · `sdk/dist/svm/venues/pda-memo.d.ts`

Tune the process-wide PDA-derivation memo. Call once at startup - the memo is
a single process-lifetime cache shared across every CLMM/DLMM venue family,
so this is global configuration, not per-call.

A consumer whose pool universe is large enough to approach the default 100 000
ceiling (each entry is one small `(program, pool, window)`-shaped key) can
raise `maxEntries` to keep more derivations warm. Raising it is cheap - the
memo only grows as far as real derivations demand. LOWERING it below the
current population evicts the oldest entries eagerly to honor the new bound
immediately (correct addresses always re-derive on the next miss).

* @throws if `maxEntries` is not a positive integer.

```typescript theme={null}
export declare function configurePdaMemo(config: PdaMemoConfig): void;
```

### `getPdaMemoMaxEntries`

*Function* · `sdk/dist/svm/venues/pda-memo.d.ts`

The memo's current maximum-entry cap (default `DEFAULT_PDA_MEMO_MAX_ENTRIES`).

```typescript theme={null}
export declare function getPdaMemoMaxEntries(): number;
```

### `DEFAULT_PDA_MEMO_MAX_ENTRIES`

*Variable* · `sdk/dist/svm/venues/pda-memo.d.ts`

Default belt-and-suspenders cap on the memo's size - the real steady-state
population is a small, bounded set of distinct (program, pool, window)
tick-array/bin-array keys plus one oracle/bitmap/tick-array-map key per
pool (tens of entries per actively-traded pool, across all eleven
families), so this ceiling is never expected to bind in practice. A
consumer running an unusually large pool universe can raise it via
`configurePdaMemo`.

```typescript theme={null}
DEFAULT_PDA_MEMO_MAX_ENTRIES = 100000
```

### `PdaMemoConfig`

*Interface* · `sdk/dist/svm/venues/pda-memo.d.ts`

Options for `configurePdaMemo`.

```typescript theme={null}
export interface PdaMemoConfig {
    maxEntries: number;
}
```

### `listVenues`

*Function* · `sdk/dist/svm/venues/registry.d.ts`

Known venue slugs, in table order.

```typescript theme={null}
export declare function listVenues(): string[];
```

### `venueAdapter`

*Function* · `sdk/dist/svm/venues/registry.d.ts`

Looks up a venue adapter by slug; throws listing the known slugs.

```typescript theme={null}
export declare function venueAdapter(slug: string): SvmVenueAdapter;
```

### `RegisteredVenueSlug`

*Type* · `sdk/dist/svm/venues/registry.d.ts`

The registered venue slugs, as a literal union - what svm/accessors.ts builds its tree from.

```typescript theme={null}
export type RegisteredVenueSlug = keyof typeof adaptersTyped;
```

### `SCALE_COMMON_TOKEN_PROGRAM`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
TOKEN_PROGRAM: Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">
```

### `TOKEN_2022_PROGRAM`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
TOKEN_2022_PROGRAM: Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">
```

### `ASSOCIATED_TOKEN_PROGRAM`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
ASSOCIATED_TOKEN_PROGRAM: Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">
```

### `SYSTEM_PROGRAM`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
SYSTEM_PROGRAM: Address<"11111111111111111111111111111111">
```

### `SCALE_AMM_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
SCALE_AMM_PROGRAM_ID: Address<"SCALEwAvEK5gtkdHiFzXfPgtk2YwJxPDzaV3aDmR7tA">
```

### `SCALE_VMM_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
SCALE_VMM_PROGRAM_ID: Address<"SCALEWoRSpVZpMRqHEcDfNvBh3nUSe34jDr9r689gLa">
```

### `BUY_DISCRIMINATOR`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

Anchor global instruction discriminators (sha256("global:\<name>")\[0..8]).

```typescript theme={null}
BUY_DISCRIMINATOR: Uint8Array<ArrayBuffer>
```

### `SELL_DISCRIMINATOR`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
SELL_DISCRIMINATOR: Uint8Array<ArrayBuffer>
```

### `FEE_BENEFICIARY_SLOTS`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
FEE_BENEFICIARY_SLOTS = 5
```

### `CONFIG_SEED`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

The literal ASCII seed both programs' PlatformConfig PDA uses (seeds=\["config"]).

```typescript theme={null}
CONFIG_SEED: Uint8Array<ArrayBuffer>
```

### `POOL_SEED`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

The literal ASCII seed scale\_amm's own (non-VMM-migrated) Pool PDA uses (seeds=\["pool", owner, mint\_a, mint\_b]).

```typescript theme={null}
POOL_SEED: Uint8Array<ArrayBuffer>
```

### `CURVE_CONSTANT_PRODUCT`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

CurveType::ConstantProduct - the only variant this adapter supports (see module doc).

```typescript theme={null}
CURVE_CONSTANT_PRODUCT = 0
```

### `SCALE_CURVE_HELPER_NAME`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

The shared quote-curve helper, deduped BY NAME across both scale-amm and scale-vmm
(byte-identical source - the
two programs' math is identical, only account layouts differ). `dir` is 0 for
aToB (buy: fee on input) and nonzero for bToA (sell: fee on gross output).

```typescript theme={null}
SCALE_CURVE_HELPER_NAME = "qScaleCurve"
```

### `SCALE_CURVE_HELPER_SOURCE`

*Variable* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
SCALE_CURVE_HELPER_SOURCE: string
```

### `scaleCommonReadUintLE`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
export declare function readUintLE(data: Uint8Array, offset: number, width: number): bigint;
```

### `pubkeyAt`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
export declare function pubkeyAt(data: Uint8Array, offset: number): Address;
```

### `readFeeBeneficiaries`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

Reads all FEE\_BENEFICIARY\_SLOTS entries unconditionally (inactive slots are zero-inited).

```typescript theme={null}
export declare function readFeeBeneficiaries(data: Uint8Array, offset: number): FeeBeneficiary[];
```

### `ata`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

Associated Token Account address: PDA(\[owner, tokenProgram, mint], ASSOCIATED\_TOKEN\_PROGRAM).

```typescript theme={null}
export declare function ata(owner: Address, mint: Address, tokenProgram: Address): Promise<Address>;
```

### `detectTokenProgram`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

Which token program serves this mint, from its account data alone - the SAME
detection + gate the SDK's pumpswap adapter uses (a classic layout is exactly 82
bytes; an extensionless token-2022 mint is indistinguishable from it, but neither Scale
program is known to interact with such a mint in practice, so this stays conservative
like pumpswap's own copy). A TransferFeeConfig extension makes real wire amounts
diverge from the quote (a portion of every transfer is withheld by the mint itself), so
such mints are rejected rather than mis-quoted.

```typescript theme={null}
export declare function detectTokenProgram(mint: Address, data: Uint8Array, owner?: Address): Address;
```

### `computeScaleQuote`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

TS mirror of the `qScaleCurve` SauceScript helper - see module doc for the derivation.

```typescript theme={null}
export declare function computeScaleQuote(state: ScaleCurveState, amountIn: bigint, direction: ScaleDirection): bigint;
```

### `scaleDepthReserves`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

Effective (reserveIn, reserveOut) for the relative-depth filter - the VIRTUAL reserves the curve above actually prices against.

```typescript theme={null}
export declare function scaleDepthReserves(state: ScaleCurveState, direction: ScaleDirection): {
    reserveIn: bigint;
    reserveOut: bigint;
};
```

### `scaleContinuousFees`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

Continuous-oracle fee model (measurement only).

```typescript theme={null}
export declare function scaleContinuousFees(state: ScaleCurveState, direction: ScaleDirection): {
    gammaPpm: bigint;
    muPpm: bigint;
};
```

### `pda`

*Function* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
declare function pda(seeds: (Address | Uint8Array)[], programAddress: Address): Promise<Address>;
```

### `FeeBeneficiary`

*Interface* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
export interface FeeBeneficiary {
    wallet: Address;
    shareBps: number;
}
```

### `ScaleDirection`

*Type* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
export type ScaleDirection = "aToB" | "bToA";
```

### `ScaleCurveState`

*Interface* · `sdk/dist/svm/venues/scale-common.d.ts`

```typescript theme={null}
export interface ScaleCurveState {
    reservesA: bigint;
    reservesB: bigint;
    shift: bigint;
    platformFeeBps: bigint;
    shareBps: readonly bigint[];
}
```

### `mulDivDown`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

floor(a\*n/d) - the engine's DIV rule (a zero divisor yields 0, never throws), matched here for parity with the on-chain fragment.

```typescript theme={null}
export declare function mulDivDown(a: bigint, n: bigint, d: bigint): bigint;
```

### `mulDivUp`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

ceil(a\*n/d), 0 on a zero divisor (engine DIV-rule parity).

```typescript theme={null}
export declare function mulDivUp(a: bigint, n: bigint, d: bigint): bigint;
```

### `divUpRaw`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

ceil(a/d), 0 on a zero divisor (engine DIV-rule parity).

```typescript theme={null}
export declare function divUpRaw(a: bigint, d: bigint): bigint;
```

### `mulDown`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function mulDown(a: bigint, b: bigint): bigint;
```

### `mulUp`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function mulUp(a: bigint, b: bigint): bigint;
```

### `divDown`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function divDown(a: bigint, b: bigint): bigint;
```

### `divUp`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function divUp(a: bigint, b: bigint): bigint;
```

### `complement`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function complement(a: bigint): bigint;
```

### `calcWrappedAmount`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function calcWrappedAmount(amount: bigint, token: StabbleTokenScale): bigint;
```

### `calcUnwrappedAmount`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function calcUnwrappedAmount(amount: bigint, token: StabbleTokenScale): bigint;
```

### `calcRoundedAmount`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function calcRoundedAmount(amount: bigint, token: StabbleTokenScale): bigint;
```

### `decodeStabbleVault`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function decodeStabbleVault(pool: Address, data: Uint8Array | null): StabbleVaultInfo;
```

### `decodeStabblePoolCommon`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function decodeStabblePoolCommon(pool: Address, data: Uint8Array | null, programLabel: string, tokensOffset: number, tokenSize: number, weighted: boolean, minLength: number): {
    vault: Address<string>;
    mint: Address<string>;
    authorityBump: number;
    isActive: boolean;
    tokens: (StabblePoolTokenBase & {
        weight?: bigint;
    })[];
};
```

### `createProgramAddress`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

sha256(seeds... || programId || "ProgramDerivedAddress") - the raw
create\_program\_address with a KNOWN bump (never find\_program\_address:
would be wrong if the stored bump isn't the canonical one, and here it's
always read straight off the Vault account, never searched).

```typescript theme={null}
export declare function createProgramAddress(seeds: Uint8Array[], programId: Address): Address;
```

### `deriveStabbleVaultAuthority`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

vault\_authority = create\_program\_address(\["vault\_authority", vault, \[bump]], VAULT\_PROGRAM\_ID) - verified against live mainnet vaults.

```typescript theme={null}
export declare function deriveStabbleVaultAuthority(vault: Address, authorityBump: number): Address;
```

### `findStabbleAta`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

Canonical ATA(owner, mint) under the classic SPL Token program - a real find\_program\_address (off-curve search), needed once per pool at fetch time.

```typescript theme={null}
export declare function findStabbleAta(owner: Address, mint: Address): Promise<Address>;
```

### `stableCalcInvariantN`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

calc\_invariant - Newton-Raphson D, \<=64 rounds, converged when |D - Dprev| \<= 100 (NOT 1 - Stabble's own default threshold, distinct from the 2-coin curve's threshold of 1).

```typescript theme={null}
export declare function stableCalcInvariantN(amplification: bigint, balances: readonly bigint[]): bigint;
```

### `stableGetBalanceGivenInvariant`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

get\_token\_balance\_given\_invariant\_n\_all\_other\_balances - cold start (the venue's own initial guess), see stableSolveY for the shared Newton loop.

```typescript theme={null}
export declare function stableGetBalanceGivenInvariant(amplification: bigint, balances: readonly bigint[], invariant: bigint, excludedBalance: bigint): bigint;
```

### `stableGetBalanceGivenInvariantWarm`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

Ladder warm-start variant: same Newton recursion, starting from a caller-supplied y0 (the previous rung's converged y) instead of the cold initial guess. Passing y0 = invariant reproduces the cold start exactly.

```typescript theme={null}
export declare function stableGetBalanceGivenInvariantWarm(amplification: bigint, balances: readonly bigint[], invariant: bigint, excludedBalance: bigint, y0: bigint): bigint;
```

### `stableCalcOutGivenIn`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

calc\_out\_given\_in - the exact-in quote (wrapped units, no fee applied yet). Returns 0 (not throw) on a degenerate/dust input the venue's own checked\_sub would fail on, matching the engine's div-by-zero-yields-0 convention used throughout this codebase for quote fragments.

```typescript theme={null}
export declare function stableCalcOutGivenIn(amplification: bigint, balances: readonly bigint[], tokenIndexIn: number, tokenIndexOut: number, amountIn: bigint, invariant: bigint): bigint;
```

### `stableGetAmplification`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

get\_amplification: linear ramp interpolation, clamped at the ramp window's ends (60s-quantized elapsed, matching the on-chain `checked_div(60)?.checked_mul(60)?`).

```typescript theme={null}
export declare function stableGetAmplification(ampInitialFactor: number, ampTargetFactor: number, rampStartTs: bigint, rampStopTs: bigint, currentTs: bigint): bigint;
```

### `stableDHelperSource`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

SauceScript SOURCE for the N-token D-Newton ALONE (calc\_invariant) - the
ladder's warm-start split of `stableQuoteHelperSource`: an N-token pool's
D depends only on the reserves, so it is computed ONCE per trade (in
`emitSetup`), not once per rung. Same \<=64 rounds / converge |Δ|\<=100 as
the combined helper; see that function's doc for the ceiling-division and
zero-divisor conventions (identical here).

```typescript theme={null}
export declare function stableDHelperSource(n: number): {
    name: string;
    source: string;
};
```

### `stableYWarmHelperSource`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

SauceScript SOURCE for the excluded-balance Y-Newton ALONE, WARM-STARTABLE
from a caller-supplied `y0` (the ladder's warm-start split of
`stableQuoteHelperSource`): identical math to
`stableGetBalanceGivenInvariant` EXCEPT the cold initial-guess formula is
replaced by the caller's `y0` - passing `y0 = d` (the venue's own cold
start) reproduces the venue-exact final quote; a ladder thread the
PREVIOUS rung's converged y instead, cutting iterations to \~1-2 (a larger
cumulative input means a smaller y, so the previous rung's y still
approaches the fixed point from above - exactly `stableYW`'s justification
for the 2-coin case, unchanged by generalizing to N tokens). Same
ceiling-division / zero-divisor conventions as `stableQuoteHelperSource`.

```typescript theme={null}
export declare function stableYWarmHelperSource(n: number): {
    name: string;
    source: string;
};
```

### `stableQuoteHelperSource`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function stableQuoteHelperSource(n: number): {
    name: string;
    source: string;
};
```

### `isqrtFloor`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

Integer floor(sqrt(n)), Newton's method. Exported (like every other helper
in this module) so its byte-identity and iteration count are directly
testable - see stabble-isqrt.test.ts.

The seed `1n << ceil(bits/2)` (bits = n's bit length) is picked so the
FIRST iterate already sits >= floor(sqrt(n)) for every n >= 2: n \< 2^bits
implies sqrt(n) \< 2^(bits/2) \<= 2^ceil(bits/2), so the seed's square,
2^(2\*ceil(bits/2)), is >= 2^bits > n. Newton's iteration for floor-sqrt is
monotonically non-increasing once started at or above the true root and
converges to exactly floor(sqrt(n)) regardless of the starting point (the
classical property this loop has always relied on - only the seed changed
here) - so the RESULT for every n is unchanged; only the number of
iterations needed drops, from \~bits/2 with the old `x = n` seed (each
early iteration barely halves x) to \~5-8 total once seeded this close to
the root. This matters here specifically because `weightedPowUp`'s
fractional-exponent path feeds `sqrtInternalCeil` an ISCALE(1e18)-inflated
operand - routinely \~110-130 bits - so the old seed cost \~55-70 slow
halving iterations per sqrt call, repeated up to POW\_FRAC\_BITS(64) times
per `weightedPowUp` invocation.

```typescript theme={null}
export declare function isqrtFloor(n: bigint): bigint;
```

### `weightedPowUp`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

OVER-estimate of base^exponent (base in (0, ONE], exponent >= 0, both ONE(1e9)-scaled).

```typescript theme={null}
export declare function weightedPowUp(base: bigint, exponent: bigint): bigint;
```

### `weightedCalcOutGivenIn`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

calc\_out\_given\_in (wrapped units) - null (not throw) once amountIn exceeds MAX\_IN\_RATIO, the venue's real hard capacity cap (`None` on-chain, would panic the instruction; the ladder must clamp to this, never quote past it).

```typescript theme={null}
export declare function weightedCalcOutGivenIn(balanceIn: bigint, weightIn: bigint, balanceOut: bigint, weightOut: bigint, amountIn: bigint): bigint | null;
```

### `weightedPowUpSource`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

SauceScript SOURCE mirror of `weightedPowUp` - since `weightIn`/`weightOut`
are pool constants (immutable in practice; treated as such here, matching
this codebase's convention of baking genuinely-immutable curve constants),
the exponent - and therefore the ENTIRE bit-decomposition schedule (how
many squarings for the integer part, how many sqrt iterations for the
fraction, and which of them land a "multiply into result" - is fully
determined at COMPILE TIME. So unlike the runtime loop `weightedPowUp`
runs in TS, the emitted fragment needs NO loop and NO data-dependent
branch at all: this function TRACES the same schedule off-chain and
emits a flat, unrolled sequence of ceiling-sqrt/ceiling-multiply lines - cheaper AND simpler than a generic runtime loop, and naturally short for
"nice" ratios (50/50, 80/20, ...) since the fractional remainder can hit
exactly 0 after only 1-2 iterations. `baseVar` must already be bound to
the ONE(1e9)-scaled runtime base (`divUp(balanceIn, balanceIn+amountIn)`);
`out` becomes a `const` holding the ONE-scaled, ceiling-biased power.
The three exact-integer special cases (ONE/TWO/THREE/FOUR) reproduce the
real program's own fast path bit-for-bit (mulUp composition, no
approximation); everything else uses the conservative sqrt ladder (see
`weightedPowUp`'s doc for the accuracy/conservatism proof).

```typescript theme={null}
export declare function weightedPowUpSource(weightIn: bigint, weightOut: bigint, baseVar: string, out: string): string[];
```

### `weightedCoreQuoteLines`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

Full weighted-swap core quote (wrapped-space, NO fee applied yet - the
caller applies swap\_fee, matching the real program's own function
boundary): `${outVar}` becomes the wrapped gross output for a wrapped
gross-input expression `wrappedXExpr` (0 when the expression is 0, never
negative, never throws on a zero/degenerate denominator - matches the
engine's DIV rule). `tag` must be unique per call site (rung index or
"final") so nested locals across multiple emissions in one fragment don't
collide.

```typescript theme={null}
export declare function weightedCoreQuoteLines(tag: string, balInVar: string, balOutVar: string, weightIn: bigint, weightOut: bigint, wrappedXExpr: string, outVar: string): string[];
```

### `STABLE_SWAP_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABLE_SWAP_PROGRAM_ID: Address<"swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ">
```

### `WEIGHTED_SWAP_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
WEIGHTED_SWAP_PROGRAM_ID: Address<"swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW">
```

### `STABBLE_VAULT_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABBLE_VAULT_PROGRAM_ID: Address<"vo1tWgqZMjG61Z2T9qUaMYKqZ75CYzMuaZ2LZP1n7HV">
```

### `STABBLE_TOKEN_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABBLE_TOKEN_PROGRAM_ID: Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">
```

### `STABBLE_TOKEN_2022_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABBLE_TOKEN_2022_PROGRAM_ID: Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">
```

### `STABBLE_ATA_PROGRAM_ID`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABBLE_ATA_PROGRAM_ID: Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">
```

### `STABBLE_POOL_DISCRIMINATOR`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

sha256("account:Pool")\[..8] - shared by BOTH variants (Anchor discriminators are name-, not program-, keyed; verified against live pool accounts of both programs).

```typescript theme={null}
STABBLE_POOL_DISCRIMINATOR: Uint8Array<ArrayBuffer>
```

### `STABBLE_VAULT_DISCRIMINATOR`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

sha256("account:Vault")\[..8].

```typescript theme={null}
STABBLE_VAULT_DISCRIMINATOR: Uint8Array<ArrayBuffer>
```

### `STABBLE_SWAP_DISCRIMINATOR`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

sha256("global:swap")\[..8] - the v1 `swap(amount_in: Option<u64>, minimum_amount_out: u64)` entry point.

```typescript theme={null}
STABBLE_SWAP_DISCRIMINATOR: Uint8Array<ArrayBuffer>
```

### `STABBLE_ONE`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABBLE_ONE = 1000000000n
```

### `StabbleTokenScale`

*Interface* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export interface StabbleTokenScale {
    scalingUp: boolean;
    scalingFactor: bigint;
}
```

### `StabblePoolTokenBase`

*Interface* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export interface StabblePoolTokenBase {
    mint: Address;
    decimals: number;
    scalingUp: boolean;
    scalingFactor: bigint;
    balance: bigint;
}
```

### `StabbleVaultInfo`

*Interface* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export interface StabbleVaultInfo {
    admin: Address;
    withdrawAuthority: Address;
    withdrawAuthorityBump: number;
    authorityBump: number;
    isActive: boolean;
    beneficiary: Address;
    beneficiaryFee: bigint;
}
```

### `assertStabbleU64AmountIn`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
declare function assertU64AmountIn(amountIn: bigint, label: string): void;
```

### `STABBLE_U64_MAX`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
U64_MAX: bigint
```

### `STABLE_AMP_PRECISION`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABLE_AMP_PRECISION = 1000n
```

### `STABLE_MIN_TOKENS`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABLE_MIN_TOKENS = 2
```

### `STABLE_MAX_TOKENS`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
STABLE_MAX_TOKENS = 5
```

### `WEIGHTED_MAX_IN_RATIO`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
WEIGHTED_MAX_IN_RATIO = 300000000n
```

### `WEIGHTED_MIN_TOKENS`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
WEIGHTED_MIN_TOKENS = 2
```

### `WEIGHTED_MAX_TOKENS`

*Variable* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
WEIGHTED_MAX_TOKENS = 4
```

### `stabbleStableSwapCalcRoundedAmount`

*Function* · `sdk/dist/svm/venues/stabble-common.d.ts`

```typescript theme={null}
export declare function calcRoundedAmount(amount: bigint, token: StabbleTokenScale): bigint;
```

### `SvmHelperFn`

*Interface* · `sdk/dist/svm/venues/stable-helpers.d.ts`

The declared-helper shape an SvmRoute venue contributes to codegen (the
generator dedupes helpers by `name`).

The shared stable-curve Newton helper SOURCES that used to live here
(`STABLE_D_HELPER`/`STABLE_YW_HELPER` and their TS mirrors
`stableComputeD`/`stableComputeYWarm`) were merge-decomposition ladder
internals - only ladder rung walks consumed them - and moved out with the
ladders themselves to the consuming recipes package. This interface stays
because it is the generic contract, not the math.

```typescript theme={null}
export interface SvmHelperFn {
    name: string;
    source: string;
}
```

### `AccountLoader`

*Type* · `sdk/dist/svm/venues/types.d.ts`

RPC-or-fixture account source: address in, raw account data out (null when
the account does not exist). fetchPoolConfig takes one of these so LiteSVM
fixture tests run without any RPC.

```typescript theme={null}
export type AccountLoader = (address: Address) => Promise<Uint8Array | null>;
```

### `OwnedAccountLoader`

*Type* · `sdk/dist/svm/venues/types.d.ts`

The same source, WITH the owning program.

Owner-based classification is the only correct way to tell a legacy SPL mint from a Token-2022
one - an extensionless T22 mint is byte-identical to a classic 82-byte mint, so no amount of data
inspection can separate them. `AccountLoader` drops the owner at this boundary, which made that
classification structurally impossible for an adapter; this hands it through.

Additive on purpose: the data-only loader stays the argument every adapter takes, so adapters
move over one at a time rather than in one 64-file sweep.

```typescript theme={null}
export type OwnedAccountLoader = (address: Address) => Promise<{
    data: Uint8Array;
    owner: Address;
} | null>;
```

### `AccountBytesMap`

*Type* · `sdk/dist/svm/venues/types.d.ts`

Point-in-time account state keyed by base58 address - what referenceQuote
reads instead of the chain.

```typescript theme={null}
export type AccountBytesMap = Record<string, Uint8Array>;
```

### `PoolConfig`

*Interface* · `sdk/dist/svm/venues/types.d.ts`

Base shape of a decoded pool configuration. Each adapter extends it with
the venue-specific fields its quote emitter and swap builder need (vault
addresses, fee parameters, curve constants, ...) - everything is resolved
once, off-chain, by fetchPoolConfig.

```typescript theme={null}
export interface PoolConfig {
    venue: string;
    pool: Address;
}
```

### `VenueAccount`

*Interface* · `sdk/dist/svm/venues/types.d.ts`

One account attached to the generated program. `ref` is the symbolic
account-plan ref used in generated SauceScript; `address` is present when
the adapter resolved it from PoolConfig and absent for caller-resolved refs
(the user's token accounts / owner from SwapUser).

```typescript theme={null}
export interface VenueAccount {
    ref: string;
    address?: Address;
    writable?: boolean;
    signer?: boolean;
    optional?: boolean;
}
```

### `SwapUser`

*Interface* · `sdk/dist/svm/venues/types.d.ts`

User-side refs for buildSwap. Refs, not addresses: the caller resolves them
(resolveAccounts) when sending.

```typescript theme={null}
export interface SwapUser {
    outAta: string;
    inAta: string;
    owner: string;
}
```

### `VenueSwap`

*Interface* · `sdk/dist/svm/venues/types.d.ts`

A ready-to-CPI venue swap: raw instruction data plus its ordered accounts.
Venue-level min\_out is always 1 - the recipe's post-swap outAta delta check
enforces the real bound.

```typescript theme={null}
export interface VenueSwap {
    programId: Address;
    data: Uint8Array;
    accounts: VenueAccount[];
}
```

### `SvmVenueAdapter`

*Interface* · `sdk/dist/svm/venues/types.d.ts`

```typescript theme={null}
export interface SvmVenueAdapter {
    slug: string;
    kind: "constant-product" | "stable" | "sqrt-price";
    programId: Address;
    fetchPoolConfig(load: AccountLoader, pool: Address): Promise<PoolConfig>;
    quoteAccounts(cfg: PoolConfig): VenueAccount[];
    emitQuote(cfg: PoolConfig, i: number, amountIn: bigint): string;
    buildSwap(cfg: PoolConfig, user: SwapUser, amountIn: bigint): VenueSwap;
    referenceQuote(cfg: PoolConfig, state: AccountBytesMap, amountIn: bigint, now: bigint): bigint;
}
```
