import { type Selectable } from 'kysely';
import type * as Db from '../Db.js';
import type * as db_Schema from '../Schema.js';
/** Columns of the `routes_transfers` table. */
export type Table = db_Schema.RoutesTransfer;
/** A stored route transfer. */
export type Record = Selectable
;
/** Time retained for late source registration after a subsidized quote expires. */
export declare const subsidyCommitmentRecoveryTtlMs = 86400000;
/** Returns whether an awaiting-source subsidy commitment is past its registration window. */
export declare function isSubsidyCommitmentExpired(record: Record): boolean;
/**
* Ownership filter derived from the API-key principal, never from the
* request. A `projectId` narrows reads to that project; organization-attributed
* keys omit it and see every project in their organization and environment.
*/
export type Owner = {
/** Key environment. */
environment: Record['environment'];
/** Owning organization id (`org_…`). */
orgId: string;
/** Attributed project id, for project-attributed keys. */
projectId?: string | undefined;
};
/** Aggregates active transfer states for bounded operational metrics. */
export declare function summarizeStates(db: Db.Db, options: summarizeStates.Options): Promise<{
count: string;
environment: "production" | "sandbox";
method: "depositAddress" | "transaction";
oldestStatusUpdatedAt: string;
providerId: string;
reason: string | null;
status: "action-required" | "awaiting-source" | "completed" | "expired" | "processing" | "refunded" | "refunding";
}[]>;
export declare namespace summarizeStates {
/** Active-state aggregation options. */
type Options = {
/** Lifecycle statuses still owned by platform processing or recovery. */
statuses: readonly Record['status'][];
};
}
/** Inserts a transfer row. Callers commit the matching event in the same transaction. */
export declare function insert(db: Db.Db, record: Record): Promise;
/** Gets a transfer by id without ownership scoping (domain and reconciler use). */
export declare function get(db: Db.Db, id: string): Promise;
/** Lists processing transfers for one provider, oldest first. */
export declare function listProcessing(db: Db.Db, options: listProcessing.Options): Promise;
export declare namespace listProcessing {
/** Provider filter for one recovery scan. */
type Options = {
/** Exclusive lower bound from the prior recovery page. */
cursor?: string | undefined;
/** Maximum transfers returned in one recovery page. */
limit: number;
/** Route provider id. */
providerId: string;
};
}
/** Gets and locks a transfer for one atomic domain mutation. */
export declare function getForUpdate(db: Db.Db, id: string): Promise;
/** Persists the first verified provider-delivery boundary without a public version change. */
export declare function recordProviderDelivery(db: Db.Db, options: recordProviderDelivery.Options): Promise;
export declare namespace recordProviderDelivery {
/** Provider delivery boundary write. */
type Options = {
/** First verified provider-delivery time. */
deliveredAt: string;
/** Route transfer id (`rtr_…`). */
id: string;
};
}
/** Gets an owner-visible transfer by id; `undefined` for absent or foreign rows. */
export declare function getOwned(db: Db.Db, owner: Owner, id: string): Promise;
/**
* Lists an owner's transfers newest-first. Ids embed a timestamp, so lexical
* key order is chronological and the cursor is the last returned id.
*/
export declare function listByOwner(db: Db.Db, owner: Owner, options: listByOwner.Options): Promise;
export declare namespace listByOwner {
/** Paging and filter options. */
type Options = {
/** Exclusive lower bound: the last id of the previous page. */
cursor?: string | undefined;
/** Maximum rows to return (fetch one extra to detect a further page). */
limit: number;
/** Restricts to one lifecycle status. */
status?: Record['status'] | undefined;
};
}
/**
* Counts an owner's transfers through a capped subquery sharing the list
* filter, so the count cannot scan unboundedly. A result above `cap` means
* the true count was truncated.
*/
export declare function count(db: Db.Db, owner: Owner, options: count.Options): Promise;
export declare namespace count {
/** Count options sharing the list filter. */
type Options = {
/** Row ceiling; a result above it signals a truncated count. */
cap: number;
/** Restricts to one lifecycle status. */
status?: Record['status'] | undefined;
};
}
/** Lists filtered route transfers, newest update first. */
export declare function list(db: Db.Db, options: list.Options): Promise;
export declare namespace list {
/** Transfer filters and page bound. */
type Options = {
/** Exclusive lower bound from the previous page. */
cursor?: Cursor | undefined;
/** Restricts transfers to one route environment. */
environment?: Record['environment'] | undefined;
/** Restricts transfers to any listed route environment. */
environments?: readonly Record['environment'][] | undefined;
/** Restricts transfers to records with a positive Tempo subsidy. */
hasSubsidy?: true | undefined;
/** Maximum rows returned. */
limit: number;
/** Restricts transfers to one route method. */
method?: Record['method'] | undefined;
/** Restricts transfers to any listed route method. */
methods?: readonly Record['method'][] | undefined;
/** Restricts transfers to one organization. */
orgId?: string | undefined;
/** Restricts transfers to one project. */
projectId?: string | undefined;
/** Restricts transfers to one provider. */
providerId?: string | undefined;
/** Restricts transfers to any listed provider. */
providerIds?: readonly string[] | undefined;
/** Exact transfer id or transaction reference. */
query?: string | undefined;
/** Restricts transfers to one source chain. */
sourceChainId?: string | undefined;
/** Restricts transfers to any listed source chain. */
sourceChainIds?: readonly string[] | undefined;
/** Restricts transfers to one lifecycle status. */
status?: Record['status'] | undefined;
/** Restricts transfers to any listed lifecycle status. */
statuses?: readonly Record['status'][] | undefined;
};
/** Cursor fields for the last transfer on the previous page. */
type Cursor = {
/** Transfer id, used as a deterministic tie-breaker. */
id: string;
/** Latest material update time. */
updatedAt: string;
};
}
/** Summarizes transfer work across the selected filters. */
export declare function summarize(db: Db.Db, options?: summarize.Options): Promise;
export declare namespace summarize {
/** Attribution and route filters. */
type Options = {
/** Restricts transfers to one route environment. */
environment?: Record['environment'] | undefined;
/** Restricts transfers to any listed route environment. */
environments?: readonly Record['environment'][] | undefined;
/** Restricts transfers to one route method. */
method?: Record['method'] | undefined;
/** Restricts transfers to any listed route method. */
methods?: readonly Record['method'][] | undefined;
/** Restricts transfers to one organization. */
orgId?: string | undefined;
/** Restricts transfers to one project. */
projectId?: string | undefined;
/** Restricts transfers to one provider. */
providerId?: string | undefined;
/** Restricts transfers to any listed provider. */
providerIds?: readonly string[] | undefined;
/** Restricts transfers to one source chain. */
sourceChainId?: string | undefined;
/** Restricts transfers to any listed source chain. */
sourceChainIds?: readonly string[] | undefined;
};
/** Current transfer work totals. */
type Result = {
/** Transfers that require operator action. */
actionRequired: number;
/** Transfers currently owned by platform processing or recovery. */
inProgress: number;
/** When the oldest active transfer entered its current status. */
oldestActiveAt: string | null;
};
}
/** Returns the Tempo-funded subsidy recorded for one outbound transfer. */
export declare function subsidies(record: Record): {
amount: {
baseUnits: string;
currency: string;
decimals: number;
formatted: string;
};
provider: 'tempo';
token: {
address: string;
currency: string;
decimals: number;
name: string;
standard: string;
symbol: string;
tokenKey: string;
verified: boolean;
};
}[];
/** Lists completed production transfer subsidies awaiting Stripe acknowledgement. */
export declare function listUnreportedSubsidies(db: Db.Db, options?: listUnreportedSubsidies.Options): Promise;
export declare namespace listUnreportedSubsidies {
/** Options for the outbound Routes subsidy reporting scan. */
type Options = {
/** Maximum rows to return. */
limit?: number | undefined;
};
}
/** Stores the effective timestamp after Stripe acknowledges an outbound subsidy. */
export declare function markSubsidyReported(db: Db.Db, id: string, meteredAt: string): Promise;
/** Returns whether an organization has an outbound subsidy awaiting resolution or reporting. */
export declare function hasUnreportedSubsidies(db: Db.Db, orgId: string): Promise;
/** Reads outbound subsidy usage for one organization and time window. */
export declare function subsidyUsage(db: Db.Db, options: subsidyUsage.Options): Promise;
export declare namespace subsidyUsage {
/** Organization and meter-event window for outbound subsidy usage. */
type Options = {
/** Key environment to include. */
environment: Record['environment'];
/** Inclusive meter-event lower bound. */
from: string;
/** Organization whose subsidy usage is read. */
orgId: string;
/** Inclusive meter-event upper bound. */
to: string;
};
/** Outbound subsidy usage in six-decimal meter units. */
type Result = {
/** USD subsidy total in six-decimal meter units. */
amount: bigint;
/** Metered outbound subsidies. */
count: number;
};
}
/** Returns token and native inventory promised by active transfer commitments. */
export declare function subsidyReservations(db: Db.Db, options: subsidyReservations.Options): Promise;
/** Lists abandoned subsidy commitments eligible for bounded expiry. */
export declare function listExpiredSubsidyCommitments(db: Db.Db, options: listExpiredSubsidyCommitments.Options): Promise;
export declare namespace listExpiredSubsidyCommitments {
/** Expired commitment scan options. */
type Options = {
/** Latest quote expiry eligible for cleanup. */
expiredBefore: string;
/** Maximum rows returned. */
limit: number;
};
}
export declare namespace subsidyReservations {
/** Signer, chain, and token identifying one inventory pool. */
type Options = {
/** Destination subsidy signer address. */
account: string;
/** Destination EVM chain CAIP-2 id. */
chainId: string;
/** Transfer excluded while converting its commitment into a signed transaction. */
excludeId?: string | undefined;
/** Destination ERC-20 token address. */
tokenAddress: string;
};
/** Inventory promised by signed transactions that have not completed. */
type Result = {
/** Native gas amount reserved on the signer chain. */
nativeAmount: bigint;
/** Destination token amount reserved for the requested token. */
tokenAmount: bigint;
};
}
/**
* Applies a version-guarded update; `undefined` when the row moved past
* `expectedVersion` (or vanished) so the caller retries against fresh state.
*/
export declare function update(db: Db.Db, options: update.Options): Promise;
export declare namespace update {
/** Guarded update fields. */
type Options = {
/** The version the update was computed against. */
expectedVersion: number;
/** Transfer id (`rtr_…`). */
id: string;
/** Replacement private provider state; omitted keeps the stored value. */
providerState?: Record['providerState'] | undefined;
/** When provider destination delivery was first verified. */
providerDeliveredAt: Record['providerDeliveredAt'];
/** Replacement public snapshot. */
snapshot: Record['snapshot'];
/** New lifecycle status. */
status: Record['status'];
/** Customer-safe reason, or null to clear. */
statusReason: Record['statusReason'];
/** When the transfer entered its current status. */
statusUpdatedAt: Record['statusUpdatedAt'];
/** Destination subsidy signer address. */
subsidyAccount: Record['subsidyAccount'];
/** Destination token amount supplied by Tempo. */
subsidyAmount: Record['subsidyAmount'];
/** Destination subsidy chain id. */
subsidyChainId: Record['subsidyChainId'];
/** Maximum destination subsidy authorized at action creation. */
subsidyCommitmentAmount: Record['subsidyCommitmentAmount'];
/** Native gas amount reserved by the signed transaction. */
subsidyNativeAmount: Record['subsidyNativeAmount'];
/** Destination subsidy token address. */
subsidyTokenAddress: Record['subsidyTokenAddress'];
/** Destination subsidy transaction hash. */
subsidyTransactionHash: Record['subsidyTransactionHash'];
/** Mutation timestamp (ISO 8601). */
updatedAt: string;
/** The incremented version. */
version: number;
};
}
//# sourceMappingURL=routesTransfers.d.ts.map