import { type Address, type Hex } from 'viem'; import type * as Campaigns from './Campaigns.js'; /** Current mutable projection for one registered recipient. */ export type Account = { /** Arithmetic remainder carried across reward intervals. */ accrualRemainder: bigint; /** Principal permanently allocated against campaign caps. */ allocatedPrincipalAssets: bigint; /** Cumulative EarnShare entitlement. */ cumulativeEntitlement: bigint; /** Cumulative EarnShare already paid. */ cumulativePaid: bigint; /** Current delivery deferral. */ deferral?: string | undefined; /** Eligibility registration version consumed by this projection. */ eligibilityRegisteredAt?: string | undefined; /** Surviving qualified deposit lots. */ lots: Campaigns.DepositLot[]; /** Base-asset reward not yet converted into EarnShare. */ pendingRewardAssets: bigint; /** Current attributable public EarnShare balance. */ publicEarnShares: bigint; /** Current qualified EarnShare balance. */ qualifiedEarnShares: bigint; /** Registered recipient. */ recipient: Address; /** Monotonic eligibility registration order. */ registrationOrder: bigint; }; /** One canonically ordered public deposit or EarnShare transfer. */ export type Event = { /** Deposited base assets. */ assets: bigint; /** Canonical event position. */ cursor: Campaigns.EventCursor; /** EarnShare minted by the deposit. */ earnShares: bigint; /** Deposit event kind. */ kind: 'deposit'; /** Deposit receiver. */ recipient: Address; /** Block timestamp. */ timestamp: number; } | { /** Transferred EarnShare. */ amount: bigint; /** Canonical event position. */ cursor: Campaigns.EventCursor; /** Sender, or zero address for mint. */ from: Address; /** Transfer event kind. */ kind: 'transfer'; /** Block timestamp. */ timestamp: number; /** Recipient, or zero address for burn. */ to: Address; }; /** Returns a deterministic checksum for a run's complete closing account state. */ export declare function checksum(accounts: readonly Account[]): Hex; /** Restores one calculation projection from a durable run snapshot. */ export declare function fromSnapshot(snapshot: Campaigns.AccountSnapshot): Account; /** Serializes one calculation projection for crash-safe run recovery. */ export declare function snapshot(account: Account): Campaigns.AccountSnapshot; /** Applies ordered public events and campaign cap allocation to registered accounts. */ export declare function apply(options: apply.Options): apply.Result; /** Reconstructs surviving pre-campaign deposit lots before permanently allocating campaign caps. */ export declare function bootstrap(options: bootstrap.Options): apply.Result; /** Reconciles registration history pagewise and checkpoints replay state without retaining events. */ export declare function reconcilePages(options: reconcilePages.Options): Promise; export declare namespace reconcilePages { /** One historical page with optional registration traversal progress. */ type Page = { /** Registration-order recipient represented by this page. */ allocationRecipient?: Address | undefined; /** Historical events applied by this page. */ events: readonly Event[]; }; /** Serializable historical replay state. */ type Checkpoint = { /** Recipient whose registration-ordered deposit page was last applied. */ allocationRecipient?: Address | undefined; /** Replayed account projections before campaign cap allocation. */ accounts: readonly Campaigns.AccountSnapshot[]; /** Remaining FIFO-consumed shares while allocating surviving deposits. */ consumedEarnShares?: Readonly> | undefined; /** Final event included in this pass. */ cursor?: Campaigns.EventCursor | undefined; /** Gross deposited shares keyed by normalized recipient. */ depositedEarnShares: Readonly>; /** Historical reducer pass. */ pass: 'allocation' | 'survival'; /** Final canonical event applied by the survival pass. */ replayedThrough?: Campaigns.EventCursor | undefined; }; /** Inputs for registration reconciliation over canonical event pages. */ type Options = Omit & { /** Previously persisted replay state. */ checkpoint?: Checkpoint | undefined; /** Persists replay state after one complete canonical page. */ checkpointState?: ((state: Checkpoint) => Promise | void) | undefined; /** Recreates historical pages in the ordering required by each pass. */ pages: (pass: Checkpoint['pass'], after?: Campaigns.EventCursor) => AsyncIterable; }; } /** Rebuilds deposit-derived state for new or refreshed eligibility registrations. */ export declare function reconcileRegistrations(options: reconcileRegistrations.Options): reconcileRegistrations.Result; export declare namespace reconcileRegistrations { /** Inputs for registration-driven historical reconciliation. */ type Options = Omit & { /** Current delivered account projections. */ accounts: readonly Account[]; /** Eligibility registrations and their current durable versions. */ eligible: readonly { /** Eligible reward recipient. */ recipient: Address; /** Monotonic eligibility registration order. */ registrationOrder: bigint; /** Registration version returned by the eligibility API. */ registeredAt: string; }[]; }; /** Reconciled accounts and whether any registration required replay. */ type Result = { /** Current accounts with refreshed deposit-derived state. */ accounts: readonly Account[]; /** Whether at least one registration required reconciliation. */ reconciled: boolean; }; } export declare namespace bootstrap { /** Historical replay and cap-allocation input. */ type Options = Omit & { /** Deposit order by default; registration order preserves late-registration cap priority. */ principalAllocationOrder?: 'deposit' | 'registration' | undefined; }; } export declare namespace apply { /** Projection input at one persisted cursor. */ type Options = { /** Previously delivered account states. */ accounts: readonly Account[]; /** Registered recipients with stable order. */ eligible: readonly { recipient: Address; registrationOrder: bigint; }[]; /** Canonically ordered public events. */ events: readonly Event[]; /** Addresses excluded from individual boost rewards. */ excluded: readonly Address[]; /** Per-recipient lifetime principal cap. */ perUserPrincipalCapAssets: bigint; /** Campaign lifetime principal cap. */ totalPrincipalCapAssets: bigint; }; /** Closing projection and permanently allocated campaign principal. */ type Result = { /** Closing recipient projections. */ accounts: readonly Account[]; /** Total principal permanently allocated against the campaign cap. */ allocatedPrincipalAssets: bigint; }; } /** Calculates time-weighted boost rewards for one interval. */ export declare function calculate(options: calculate.Options): calculate.Result; export declare namespace calculate { /** Time-weighted reward calculation input. */ type Options = { /** Opening base assets per EarnShare, scaled by 1e18. */ assetPerEarnShareWad: bigint; /** Opening recipient projections. */ accounts: readonly Account[]; /** Incremental boost annual rate in basis points. */ annualRateBps: number; /** Exclusive interval end timestamp. */ endsAt: number; /** Public events within the interval. */ events: readonly Event[]; /** Addresses excluded from individual rewards. */ excluded: readonly Address[]; /** Per-recipient lifetime principal cap. */ perUserPrincipalCapAssets: bigint; /** Inclusive interval start timestamp. */ startsAt: number; /** Campaign lifetime principal cap. */ totalPrincipalCapAssets: bigint; }; /** Closing projections and newly accrued base-asset rewards. */ type Result = { /** Closing recipient projections. */ accounts: readonly Account[]; /** Newly accrued base-asset rewards by recipient. */ rewards: ReadonlyMap; }; } /** Calculates one reward interval pagewise and checkpoints exact arithmetic state. */ export declare function calculatePages(options: calculatePages.Options): Promise; export declare namespace calculatePages { /** Serializable interval reducer state before reward finalization. */ type Checkpoint = { /** Account projections after the checkpointed page. */ accounts: readonly Campaigns.AccountSnapshot[]; /** Last accrued timestamp keyed by normalized recipient. */ accruedThrough: Readonly>; /** Weighted EarnShare seconds keyed by normalized recipient. */ weightedEarnShareSeconds: Readonly>; }; /** Inputs for reward calculation over canonical event pages. */ type Options = Omit & { /** Previously persisted interval reducer state. */ checkpoint?: Checkpoint | undefined; /** Persists reducer state after one complete canonical page. */ checkpointState?: ((state: Checkpoint, cursor: Campaigns.EventCursor) => Promise | void) | undefined; /** Canonical event pages beginning after the persisted cursor. */ pages: AsyncIterable; }; } /** Converts a database account into the arithmetic projection. */ export declare function fromRecord(record: fromRecord.Record): Account; export declare namespace fromRecord { /** Persisted account fields consumed by the projection. */ type Record = { accrualRemainder: string; allocatedPrincipalAssets: string; cumulativeEntitlement: string; cumulativePaid: string; deferral: string | null; eligibilityRegisteredAt: string | null; lots: readonly Campaigns.DepositLot[]; pendingRewardAssets: string; publicEarnShares: string; qualifiedEarnShares: string; recipient: Address; registrationOrder: string; }; } //# sourceMappingURL=Projection.d.ts.map